@Test public void generateAESKeyTest() { for (AES_KEYLENGTH keylength : AES_KEYLENGTH.values()) { logger.debug("Testing AES {}-bit key generation.", keylength.value()); long start = System.currentTimeMillis(); SecretKey aesKey = EncryptionUtil.generateAESKey(keylength, SECURITY_PROVIDER); long stop = System.currentTimeMillis(); logger.debug("Generated AES key: {}.", EncryptionUtil.byteToHex(aesKey.getEncoded())); logger.debug("Time: {} ms.", stop - start); assertNotNull(aesKey); assertTrue(aesKey.getAlgorithm().equals("AES")); } }
public static SecretKey generateAESKey(AES_KEYLENGTH keyLength, String securityProvider) { try { final KeyGenerator kg = KeyGenerator.getInstance("AES", securityProvider); kg.init(keyLength.value(), new SecureRandom()); byte[] encoded = kg.generateKey().getEncoded(); return new SecretKeySpec(encoded, "AES"); } catch (NoSuchAlgorithmException | NoSuchProviderException e) { logger.error("Exception while AES key generator instance creation:", e); } return null; }
EncryptionUtil { public static SecretKey generateAESKey(AES_KEYLENGTH keyLength, String securityProvider) { try { final KeyGenerator kg = KeyGenerator.getInstance("AES", securityProvider); kg.init(keyLength.value(), new SecureRandom()); byte[] encoded = kg.generateKey().getEncoded(); return new SecretKeySpec(encoded, "AES"); } catch (NoSuchAlgorithmException | NoSuchProviderException e) { logger.error("Exception while AES key generator instance creation:", e); } return null; } }
EncryptionUtil { public static SecretKey generateAESKey(AES_KEYLENGTH keyLength, String securityProvider) { try { final KeyGenerator kg = KeyGenerator.getInstance("AES", securityProvider); kg.init(keyLength.value(), new SecureRandom()); byte[] encoded = kg.generateKey().getEncoded(); return new SecretKeySpec(encoded, "AES"); } catch (NoSuchAlgorithmException | NoSuchProviderException e) { logger.error("Exception while AES key generator instance creation:", e); } return null; } private  EncryptionUtil(); }
EncryptionUtil { public static SecretKey generateAESKey(AES_KEYLENGTH keyLength, String securityProvider) { try { final KeyGenerator kg = KeyGenerator.getInstance("AES", securityProvider); kg.init(keyLength.value(), new SecureRandom()); byte[] encoded = kg.generateKey().getEncoded(); return new SecretKeySpec(encoded, "AES"); } catch (NoSuchAlgorithmException | NoSuchProviderException e) { logger.error("Exception while AES key generator instance creation:", e); } return null; } private  EncryptionUtil(); static byte[] generateIV(); static SecretKey generateAESKey(AES_KEYLENGTH keyLength, String securityProvider); static KeyPair generateRSAKeyPair(RSA_KEYLENGTH keyLength, String securityProvider); static byte[] encryptAES(byte[] data, SecretKey secretKey, byte[] initVector, String securityProvider,
			IStrongAESEncryption strongAES); static byte[] decryptAES(byte[] data, SecretKey secretKey, byte[] initVector, String securityProvider,
			IStrongAESEncryption strongAES); static byte[] encryptRSA(byte[] data, PublicKey publicKey, String securityProvider); static byte[] decryptRSA(byte[] data, PrivateKey privateKey, String securityProvider); static HybridEncryptedContent encryptHybrid(byte[] data, PublicKey publicKey, AES_KEYLENGTH aesKeyLength,
			String securityProvider, IStrongAESEncryption strongAES); static byte[] decryptHybrid(HybridEncryptedContent data, PrivateKey privateKey, String securityProvider,
			IStrongAESEncryption strongAES); static byte[] sign(byte[] data, PrivateKey privateKey, String securityProvider); static boolean verify(byte[] data, byte[] signature, PublicKey publicKey, String securityProvider); static String byteToHex(byte[] data); }
EncryptionUtil { public static SecretKey generateAESKey(AES_KEYLENGTH keyLength, String securityProvider) { try { final KeyGenerator kg = KeyGenerator.getInstance("AES", securityProvider); kg.init(keyLength.value(), new SecureRandom()); byte[] encoded = kg.generateKey().getEncoded(); return new SecretKeySpec(encoded, "AES"); } catch (NoSuchAlgorithmException | NoSuchProviderException e) { logger.error("Exception while AES key generator instance creation:", e); } return null; } private  EncryptionUtil(); static byte[] generateIV(); static SecretKey generateAESKey(AES_KEYLENGTH keyLength, String securityProvider); static KeyPair generateRSAKeyPair(RSA_KEYLENGTH keyLength, String securityProvider); static byte[] encryptAES(byte[] data, SecretKey secretKey, byte[] initVector, String securityProvider,
			IStrongAESEncryption strongAES); static byte[] decryptAES(byte[] data, SecretKey secretKey, byte[] initVector, String securityProvider,
			IStrongAESEncryption strongAES); static byte[] encryptRSA(byte[] data, PublicKey publicKey, String securityProvider); static byte[] decryptRSA(byte[] data, PrivateKey privateKey, String securityProvider); static HybridEncryptedContent encryptHybrid(byte[] data, PublicKey publicKey, AES_KEYLENGTH aesKeyLength,
			String securityProvider, IStrongAESEncryption strongAES); static byte[] decryptHybrid(HybridEncryptedContent data, PrivateKey privateKey, String securityProvider,
			IStrongAESEncryption strongAES); static byte[] sign(byte[] data, PrivateKey privateKey, String securityProvider); static boolean verify(byte[] data, byte[] signature, PublicKey publicKey, String securityProvider); static String byteToHex(byte[] data);  }