List of utility methods to do Key Pair Create
Key | generateKey() generate Key try { KeyGenerator kg = KeyGenerator.getInstance("DES"); Key key = kg.generateKey(); return key; } catch (Exception e) { e.printStackTrace(); return null; ... |
SecretKey | generateKey() generate Key KeyGenerator gen; try { gen = KeyGenerator.getInstance("AES"); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException("Failed to get generator for algorithm", e); gen.init(random); return gen.generateKey(); ... |
Key | generateKey(byte[] keyBytes) generate Key KeySpec keySpec = new DESKeySpec(keyBytes); SecretKeyFactory factory = SecretKeyFactory.getInstance(DES); return factory.generateSecret(keySpec); |
Key | generateKey(byte[] keyBytes) generate Key return new SecretKeySpec(keyBytes, AES); |
Key | generateKey(char[] password) generate Key return generateKey(password, generateSalt(128));
|
byte[] | generateKey(final SecureRandom srand) generate Key final byte[] key = new byte[256 / 8]; srand.nextBytes(key); return key; |
SecretKey | generateKey(final String password, final byte salt[]) Generates a key using the specified password and salt. if (salt.length < SALT_LENGTH) { throw new Exception("Need a salt at least length " + SALT_LENGTH + "."); return generateKey(password.toCharArray(), salt); |
Key | generateKey(SecureRandom sr, int size) generate Key byte[] bytes = new byte[size]; sr.nextBytes(bytes); return new SecretKeySpec(bytes, "AES"); |
SecretKey | generateKey(String algom, int keylength) generate Key try { KeyGenerator keygen = KeyGenerator.getInstance(algom); keygen.init(keylength); SecretKey deskey = keygen.generateKey(); return deskey; } catch (GeneralSecurityException e) { throw new RuntimeException(e); |
SecretKey | generateKey(String algorithm, int keySize) Generate a SecretKey for the given symmetric algorithm and keysize Example: CipherUtils.generateKeyPair("AES", 128) KeyGenerator secretKeyGenerator; try { secretKeyGenerator = KeyGenerator.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException(e); secretKeyGenerator.init(keySize); return secretKeyGenerator.generateKey(); ... |