public static CipherTextIvMac encrypt(byte[] plaintext,SecretKeys secretKeys) throws GeneralSecurityException {
  byte[] iv=generateIv();
  Cipher aesCipherForEncryption=Cipher.getInstance(CIPHER_TRANSFORMATION);
  aesCipherForEncryption.init(Cipher.ENCRYPT_MODE,secretKeys.getConfidentialityKey(),new IvParameterSpec(iv));
  iv=aesCipherForEncryption.getIV();
  byte[] byteCipherText=aesCipherForEncryption.doFinal(plaintext);
  byte[] ivCipherConcat=CipherTextIvMac.ivCipherConcat(iv,byteCipherText);
  byte[] integrityMac=generateMac(ivCipherConcat,secretKeys.getIntegrityKey());
  return new CipherTextIvMac(byteCipherText,iv,integrityMac);
}

public static CipherTextIvMac encrypt ( byte [ ] plaintext , SecretKeys secretKeys ) throws GeneralSecurityException { byte [ ] iv = generateIv ( ) ; Cipher aesCipherForEncryption = Cipher . getInstance ( CIPHER_TRANSFORMATION ) ; aesCipherForEncryption . init ( Cipher . ENCRYPT_MODE , secretKeys . getConfidentialityKey ( ) , new IvParameterSpec ( iv ) ) ; iv = aesCipherForEncryption . getIV ( ) ; byte [ ] byteCipherText = aesCipherForEncryption . doFinal ( plaintext ) ; byte [ ] ivCipherConcat = CipherTextIvMac . ivCipherConcat ( iv , byteCipherText ) ; byte [ ] integrityMac = generateMac ( ivCipherConcat , secretKeys . getIntegrityKey ( ) ) ; return new CipherTextIvMac ( byteCipherText , iv , integrityMac ) ; }
generates a random iv and encrypts this plain text with the given key . then attaches a hashed mac , which is contained in the ciphertextivmac class .
