public byte[] decrypt(FacesContext context,byte[] securedata){
  try {
    byte[] macBytes=new byte[macLength];
    System.arraycopy(securedata,0,macBytes,0,macBytes.length);
    byte[] iv=new byte[ivLength];
    System.arraycopy(securedata,macBytes.length,iv,0,iv.length);
    byte[] encdata=new byte[securedata.length - macBytes.length - iv.length];
    System.arraycopy(securedata,macBytes.length + iv.length,encdata,0,encdata.length);
    byte[] rawKey=convertPasswordToKey(getPasswordToSecureState(context));
    Mac mac=getMac(rawKey);
    mac.update(iv);
    mac.update(encdata);
    byte[] macBytesCalculated=mac.doFinal();
    if (Arrays.equals(macBytes,macBytesCalculated)) {
      Cipher cipher=getBlockCipherForDecryption(rawKey,iv);
      byte[] plaindata=cipher.doFinal(encdata);
      return plaindata;
    }
 else {
      if (logger.isLoggable(Level.WARNING)) {
        logger.warning("ERROR: MAC did not verify!");
      }
      return null;
    }
  }
 catch (  Exception e) {
    if (logger.isLoggable(Level.SEVERE)) {
      logger.log(Level.SEVERE,e.getMessage(),e.getCause());
    }
    throw new RuntimeException(e);
  }
}

public byte [ ] decrypt ( FacesContext context , byte [ ] securedata ) { try { byte [ ] macBytes = new byte [ macLength ] ; System . arraycopy ( securedata , 0 , macBytes , 0 , macBytes . length ) ; byte [ ] iv = new byte [ ivLength ] ; System . arraycopy ( securedata , macBytes . length , iv , 0 , iv . length ) ; byte [ ] encdata = new byte [ securedata . length - macBytes . length - iv . length ] ; System . arraycopy ( securedata , macBytes . length + iv . length , encdata , 0 , encdata . length ) ; byte [ ] rawKey = convertPasswordToKey ( getPasswordToSecureState ( context ) ) ; Mac mac = getMac ( rawKey ) ; mac . update ( iv ) ; mac . update ( encdata ) ; byte [ ] macBytesCalculated = mac . doFinal ( ) ; if ( Arrays . equals ( macBytes , macBytesCalculated ) ) { Cipher cipher = getBlockCipherForDecryption ( rawKey , iv ) ; byte [ ] plaindata = cipher . doFinal ( encdata ) ; return plaindata ; } else { if ( logger . isLoggable ( Level . WARNING ) ) { logger . warning ( "ERROR: MAC did not verify!" ) ; } return null ; } } catch ( Exception e ) { if ( logger . isLoggable ( Level . SEVERE ) ) { logger . log ( Level . SEVERE , e . getMessage ( ) , e . getCause ( ) ) ; } throw new RuntimeException ( e ) ; } }
decrypts the specified byte array using the specified password , and generates an inputstream from it . the file must be encrypted by the above method for encryption . the method also verifies the mac . it uses the iv present in the file for decryption .
