use of java.security.KeyPairGenerator in project cdap by caskdata.
the class KeyStores method generatedCertKeyStore.
/**
* Create a Java key store with a stored self-signed certificate.
* @return Java keystore which has a self signed X.509 certificate
*/
public static KeyStore generatedCertKeyStore(SConfiguration sConf, String password) {
try {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance(KEY_PAIR_ALGORITHM);
SecureRandom random = SecureRandom.getInstance(SECURE_RANDOM_ALGORITHM, SECURE_RANDOM_PROVIDER);
keyGen.initialize(KEY_SIZE, random);
// generate a key pair
KeyPair pair = keyGen.generateKeyPair();
int validity = sConf.getInt(Constants.Security.SSL.CERT_VALIDITY, VALIDITY);
X509Certificate cert = getCertificate(DISTINGUISHED_NAME, pair, validity, SIGNATURE_ALGORITHM);
KeyStore keyStore = KeyStore.getInstance(SSL_KEYSTORE_TYPE);
keyStore.load(null, password.toCharArray());
keyStore.setKeyEntry(CERT_ALIAS, pair.getPrivate(), password.toCharArray(), new java.security.cert.Certificate[] { cert });
return keyStore;
} catch (Exception e) {
throw new RuntimeException("SSL is enabled but a key store file could not be created. A keystore is required " + "for SSL to be used.", e);
}
}
use of java.security.KeyPairGenerator in project JustAndroid by chinaltz.
the class AbRsa method generateRSAKeyPair.
/**
* 随机生成RSA密钥对
* @param keyLength 密钥长度,范围:512~2048 一般1024
* @return
*/
public static KeyPair generateRSAKeyPair(int keyLength) {
try {
KeyPairGenerator kpg = KeyPairGenerator.getInstance(ALGORITHM);
kpg.initialize(keyLength);
return kpg.genKeyPair();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
use of java.security.KeyPairGenerator in project ddf by codice.
the class PkiTools method generateRsaKeyPair.
/**
* Generate new RSA public/private key pair with 2048 bit key
*
* @return new generated key pair
* @throws CertificateGeneratorException
*/
public static KeyPair generateRsaKeyPair() {
try {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM, BouncyCastleProvider.PROVIDER_NAME);
keyGen.initialize(RSA_KEY_LENGTH);
return keyGen.generateKeyPair();
} catch (Exception e) {
throw new CertificateGeneratorException("Failed to generate new public/private key pair.", e);
}
}
use of java.security.KeyPairGenerator in project hbase by apache.
the class KeyStoreTestUtil method generateKeyPair.
public static KeyPair generateKeyPair(String algorithm) throws NoSuchAlgorithmException {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance(algorithm);
keyGen.initialize(1024);
return keyGen.genKeyPair();
}
use of java.security.KeyPairGenerator in project camel by apache.
the class XmlSignatureTest method getKeyPair.
public static KeyPair getKeyPair(String algorithm, int keylength) {
KeyPairGenerator keyGen;
try {
keyGen = KeyPairGenerator.getInstance(algorithm);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
keyGen.initialize(keylength, new SecureRandom());
return keyGen.generateKeyPair();
}
Aggregations