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

KeyPairGeneratorgetKeyPairGenerator(final String algorithm)
get Key Pair Generator
return KeyPairGenerator.getInstance(algorithm);
HashMapgetKeys()
get Keys
HashMap<String, Object> map = new HashMap<String, Object>();
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA");
keyPairGen.initialize(1024);
KeyPair keyPair = keyPairGen.generateKeyPair();
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
map.put("public", publicKey);
map.put("private", privateKey);
...
intgetKeySize(final Key key)
Get the key size for the given Key .
if (key instanceof ECKey) {
    ECParameterSpec params = ((ECKey) key).getParams();
    if (params != null) {
        return params.getOrder().bitLength();
} else if (key instanceof DSAKey) {
    DSAParams params = ((DSAKey) key).getParams();
    if (params != null) {
...
intgetKeySize(PrivateKey key)
Returns the key size of the given key object in bits.
int size = -1;
if (key instanceof RSAKey) {
    RSAKey pubk = (RSAKey) key;
    size = pubk.getModulus().bitLength();
} else if (key instanceof ECKey) {
    ECKey pubk = (ECKey) key;
    size = pubk.getParams().getOrder().bitLength();
} else if (key instanceof DSAKey) {
...
KeyStoregetKeyStore()
Obtain OpenSC PKCS#11 keystore without init
return KeyStore.getInstance("PKCS11", pkcs11Provider);
KeyStoregetKeyStore()
get Key Store
if (keyStore == null) {
    String filename = System.getProperty("keyStore");
    if (filename == null) {
        return null;
    try {
        InputStream in = new BufferedInputStream(new FileInputStream(filename));
        keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
...
KeyStoregetKeyStore(byte[] bytes, char[] password)
get Key Store
ByteArrayInputStream bais = null;
try {
    bais = new ByteArrayInputStream(bytes);
    try {
        KeyStore keyStore = KeyStore.getInstance(TOLVEN_CREDENTIAL_FORMAT_PKCS12);
        keyStore.load(bais, password);
        return keyStore;
    } catch (Exception ex) {
...
KeyStoregetKeyStore(Certificate[] certificateChain, PrivateKey privateKey, char[] password)
get Key Store
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, null);
keyStore.setKeyEntry("key", privateKey, password, certificateChain);
return keyStore;
KeyStoregetKeyStore(char[] password)
get Key Store
KeyStore ks = null;
try {
    ks = getKeyStore(null, password, null, null, null);
} catch (IOException ioe) {
return ks;
KeyStoregetKeyStore(File file, char[] storePass)
get Key Store
FileInputStream ksInputStream = new FileInputStream(file);
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(ksInputStream, storePass);
return ks;