public byte[] encrypt(FacesContext context,byte[] plaindata){
  try {
    byte[] rawKey=convertPasswordToKey(getPasswordToSecureState(context));
    Cipher cipher=getBlockCipherForEncryption(rawKey);
    byte[] encdata=cipher.doFinal(plaindata);
    Mac mac=getMac(rawKey);
    byte[] iv=cipher.getIV();
    mac.update(iv);
    mac.update(encdata);
    byte[] macBytes=mac.doFinal();
    byte[] tmp=concatBytes(macBytes,iv);
    byte[] securedata=concatBytes(tmp,encdata);
    return securedata;
  }
 catch (  Exception e) {
    if (logger.isLoggable(Level.SEVERE)) {
      logger.log(Level.SEVERE,e.getMessage(),e.getCause());
    }
    throw new RuntimeException(e);
  }
}

public byte [ ] encrypt ( FacesContext context , byte [ ] plaindata ) { try { byte [ ] rawKey = convertPasswordToKey ( getPasswordToSecureState ( context ) ) ; Cipher cipher = getBlockCipherForEncryption ( rawKey ) ; byte [ ] encdata = cipher . doFinal ( plaindata ) ; Mac mac = getMac ( rawKey ) ; byte [ ] iv = cipher . getIV ( ) ; mac . update ( iv ) ; mac . update ( encdata ) ; byte [ ] macBytes = mac . doFinal ( ) ; byte [ ] tmp = concatBytes ( macBytes , iv ) ; byte [ ] securedata = concatBytes ( tmp , encdata ) ; return securedata ; } catch ( Exception e ) { if ( logger . isLoggable ( Level . SEVERE ) ) { logger . log ( Level . SEVERE , e . getMessage ( ) , e . getCause ( ) ) ; } throw new RuntimeException ( e ) ; } }
encrypts the specified plaindata using the specified password . it also stores the mac and the iv in the output . the 20 - byte mac is stored first , followed by the 8 - byte iv , followed by the encrypted contents of the file .
