public static SecretKeys generateKey() throws GeneralSecurityException {
  fixPrng();
  KeyGenerator keyGen=KeyGenerator.getInstance(CIPHER);
  keyGen.init(AES_KEY_LENGTH_BITS);
  SecretKey confidentialityKey=keyGen.generateKey();
  byte[] integrityKeyBytes=randomBytes(HMAC_KEY_LENGTH_BITS / 8);
  SecretKey integrityKey=new SecretKeySpec(integrityKeyBytes,HMAC_ALGORITHM);
  return new SecretKeys(confidentialityKey,integrityKey);
}

public static SecretKeys generateKey ( ) throws GeneralSecurityException { fixPrng ( ) ; KeyGenerator keyGen = KeyGenerator . getInstance ( CIPHER ) ; keyGen . init ( AES_KEY_LENGTH_BITS ) ; SecretKey confidentialityKey = keyGen . generateKey ( ) ; byte [ ] integrityKeyBytes = randomBytes ( HMAC_KEY_LENGTH_BITS / 8 ) ; SecretKey integrityKey = new SecretKeySpec ( integrityKeyBytes , HMAC_ALGORITHM ) ; return new SecretKeys ( confidentialityKey , integrityKey ) ; }
a function that generates random aes & hmac keys and prints out exceptions but doesn ' t throw them since none should be encountered . if they are encountered , the return value is null .
