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

KeyFactorygetKeyFactory(final String algorithm)
get Key Factory
return KeyFactory.getInstance(algorithm);
KeyFactorygetKeyFactory(final String algorithm)
get Key Factory
synchronized (keyFactories) {
    KeyFactory kf = keyFactories.get(algorithm);
    if (kf != null) {
        return kf;
    try {
        kf = KeyFactory.getInstance(algorithm, "BC");
    } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
...
KeyFactorygetKeyFactory(String keyType)
get Key Factory
if (keyType.startsWith("EC")) {
    return KeyFactory.getInstance("EC");
} else {
    return KeyFactory.getInstance(keyType);
SecretKeygetKeyFromFile(String _sFilename, String _sPassword)
getKeyFromFile - Gets key value from file, to be used for encryption/decryption
SecretKey sk = null;
File fKeyFile = new File(_sFilename);
System.out.println("DEBUG->getKeyFromFile...");
if (fKeyFile.exists()) {
    try {
        KeyStore ks = KeyStore.getInstance("JCEKS");
        ks.load(new FileInputStream(_sFilename), _sPassword.toCharArray());
        sk = (SecretKey) ks.getKey(S_KEY_ALIAS, _sPassword.toCharArray());
...
KeygetKeyFromFile(String keyFile)
get Key From File
Key kp = null;
try {
    InputStream is = new FileInputStream(keyFile);
    ObjectInputStream oos = new ObjectInputStream(is);
    kp = (Key) oos.readObject();
    oos.close();
} catch (Exception e) {
    e.printStackTrace();
...
KeyGeneratorgetKeyGenerator(String algorithm)
Get the KeyGenerator of this algorithm
try {
    return KeyGenerator.getInstance(algorithm);
} catch (NoSuchAlgorithmException e) {
    throw new IllegalArgumentException("Algorithm not found for: " + algorithm, e);
KeyManagerFactorygetKeyKeyManagerFactory(InputStream keyStore, String password, String algorithm, String keyStoreType)
get Key Key Manager Factory
KeyStore ks = KeyStore.getInstance(keyStoreType);
ks.load(keyStore, password.toCharArray());
keyStore.close();
KeyManagerFactory k = KeyManagerFactory.getInstance(algorithm);
k.init(ks, password.toCharArray());
return k;
KeyManagerFactorygetKeyKeyManagerFactoryByPfx(InputStream keyStore, String password)
get Key Key Manager Factory By Pfx
String algorithm = "sunx509";
String keyStoreType = "PKCS12";
return getKeyKeyManagerFactory(keyStore, password, algorithm, keyStoreType);
X509KeyManagergetKeyManager(KeyStore keyStore, char[] keyStorePassword)
get Key Manager
KeyManagerFactory keyManagerFactory = KeyManagerFactory
        .getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, keyStorePassword);
return (X509KeyManager) keyManagerFactory.getKeyManagers()[0];
KeyManagerFactorygetKeyManagerFactory(InputStream key, String keyPassword)
get Key Manager Factory
KeyManagerFactory kmf = null;
try {
    String keyStoreType = "BKS";
    KeyStore keyStore = KeyStore.getInstance(keyStoreType);
    keyStore.load(key, keyPassword.toCharArray());
    String kmfAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
    kmf = KeyManagerFactory.getInstance(kmfAlgorithm);
    kmf.init(keyStore, keyPassword.toCharArray());
...