2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
7 * Modifications Copyright (C) 2019 IBM.
8 * ===========================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END====================================================
24 package org.onap.aaf.certservice.cmpv2client.external;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import java.security.KeyPair;
30 import java.security.KeyPairGenerator;
31 import java.security.NoSuchAlgorithmException;
32 import java.security.SecureRandom;
34 public final class Factory {
36 private static final Logger LOGGER = LoggerFactory.getLogger(Factory.class);
37 private static final KeyPairGenerator KEY_PAIR_GENERATOR;
38 private static final SecureRandom SECURE_RANDOM;
39 private static final String KEY_ALGORITHM = "RSA";
40 private static final int KEY_LENGTH = 2048;
43 SECURE_RANDOM = new SecureRandom();
44 KeyPairGenerator tempKeygen;
46 tempKeygen = KeyPairGenerator.getInstance(KEY_ALGORITHM);
47 tempKeygen.initialize(KEY_LENGTH, SECURE_RANDOM);
48 } catch (NoSuchAlgorithmException e) {
50 LOGGER.error("Given KEY_ALGORITHM is invalid.", e);
52 KEY_PAIR_GENERATOR = tempKeygen;
58 public static KeyPair generateKeyPair() {
59 return KEY_PAIR_GENERATOR.generateKeyPair();