Code example for HashMap

Methods: put

0
        (byte) 0xA5, (byte) 0xC9, (byte) 0x93, (byte) 0xCE, (byte) 0xC1, (byte) 0x1D, (byte) 0x30, (byte) 0x73, (byte) 0xA3, (byte) 0xE1, (byte) 0x69, (byte) 0xA8, (byte) 0x11, (byte) 0x98, (byte) 0x78, (byte) 0xF3, (byte) 0xF9, 
        (byte) 0x8F, (byte) 0x04    }; 
 
 
 
    private static final HashMap<String, KeySpec> keys = new HashMap<String, KeySpec>();
    static { 
        keys.put("DH_public", new X509EncodedKeySpec(DH_public));
        keys.put("DH_private", new PKCS8EncodedKeySpec(DH_private));
        keys.put("DSA_public", new X509EncodedKeySpec(DSA_public));
        keys.put("DSA_private", new PKCS8EncodedKeySpec(DSA_private));
        keys.put("RSA_public", new X509EncodedKeySpec(RSA_public));
        keys.put("RSA_private", new PKCS8EncodedKeySpec(RSA_private));
    } 
 
    public static PrivateKey getPrivateKey(String algorithmName) throws NoSuchAlgorithmException, InvalidKeySpecException
    { 
        KeyFactory factory = KeyFactory.getInstance(algorithmName);
        return factory.generatePrivate(keys.get(algorithmName + "_private"));
    }