Java Utililty Methods Key Create

List of utility methods to do Key Create

Description

The list of methods to do Key Create are organized into topic(s).

Method

KeyManagerFactorygetKeyManagerFactory(KeyStore keystore, String password)
Given a keystore and keystore password (as generated by #pemsToKeyAndTrustStores ), return a key manager factory that contains the keystore.
KeyManagerFactory factory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
factory.init(keystore, password.toCharArray());
return factory;
KeyManagerFactorygetKeyManagerFactory(KeyStore store, char[] password)
get Key Manager Factory
KeyManagerFactory kmFactory = null;
try {
    kmFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    kmFactory.init(store, password);
} catch (NoSuchAlgorithmException nsae) {
return kmFactory;
KeyManagerFactorygetKeyManagerFactory(Map stores)
get Key Manager Factory
KeyStore keystore = (KeyStore) stores.get("keystore");
String password = (String) stores.get("keystore-pw");
return getKeyManagerFactory(keystore, password);
KeyManager[]getKeyManagers()
get Key Managers
String pass = "lib.pass";
try {
    KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(new FileInputStream("keystore.jks"), pass.toCharArray());
    KeyManagerFactory keyManagerFactory = KeyManagerFactory
            .getInstance(KeyManagerFactory.getDefaultAlgorithm());
    keyManagerFactory.init(keyStore, pass.toCharArray());
    return keyManagerFactory.getKeyManagers();
...
KeyManager[]getKeyManagers(KeyStore keyStore, String keyPassword)
get Key Managers
String alg = KeyManagerFactory.getDefaultAlgorithm();
char[] keyPass = keyPassword != null ? keyPassword.toCharArray() : null;
KeyManagerFactory fac = KeyManagerFactory.getInstance(alg);
fac.init(keyStore, keyPass);
return fac.getKeyManagers();
KeyManager[]getKeyManagers(KeyStore ks, String password)
get Key Managers
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, password.toCharArray());
return kmf.getKeyManagers();
KeyPairgetKeyPair()
get Key Pair
KeyPairGenerator kpGenerator = KeyPairGenerator.getInstance(KEY_ALGORITHM);
kpGenerator.initialize(KEY_SIZE);
KeyPair keyPair = kpGenerator.generateKeyPair();
return keyPair;
KeyPairgetKeyPair()
The method gets the key pair.
return kpg.genKeyPair();
KeyPairgetKeyPair()
Generate a RSA key pair.
KeyPairGenerator keyGen = null;
SecureRandom random = null;
try {
    keyGen = KeyPairGenerator.getInstance("RSA");
    random = SecureRandom.getInstance("SHA1PRNG", "SUN");
    keyGen.initialize(1024, random);
} catch (NoSuchAlgorithmException e) {
} catch (NoSuchProviderException e) {
...
KeyPairgetKeyPair(KeyStore keyStore, String alias, String password)
get Key Pair
Key key = keyStore.getKey(alias, password.toCharArray());
if (key instanceof PrivateKey) {
    Certificate cert = keyStore.getCertificate(alias);
    PublicKey publicKey = cert.getPublicKey();
    return new KeyPair(publicKey, (PrivateKey) key);
return null;