public OutputStream encryptStream(OutputStream outputStream) throws IOException, EncryptionError { return new EncryptingStream(getCipher(), outputStream); }
public byte[] encrypt(byte[] plaintext) throws EncryptionError { return EncryptingStream.encrypt(getCipher(), plaintext); }
public InputStream decryptStream(InputStream inputStream) throws IOException, EncryptionError { return new DecryptingStream(getCipher(), inputStream); }
public byte[] decrypt(byte[] ciphertext) throws EncryptionError { return DecryptingStream.decrypt(getCipher(), ciphertext); }
EtaEncryptingStream(OutputStream outputStream, boolean encrypt) throws IOException, EncryptionError { int blockSize = 64; // for SHA256 at least this.outputStream = outputStream; hmac = new HMAC(key); if (encrypt) { transformer = new CTRTransformer(getCipher(), null); outputStream.write(transformer.getIV()); } }
EtaDecryptingStream(InputStream inputStream) throws IOException, EncryptionError { this.inputStream = inputStream; byte[] IV = new byte[getCipher().getBlockSize()]; inputStream.read(IV); transformer = new CTRTransformer(getCipher(), IV); hmac = new HMAC(key); // We should have always block bytes in the buffer to finish: ring = new ByteRingBuffer(hmac.getLength() + 8); for (int i = 0; i < hmac.getLength(); i++) ring.put(inputStream.read()); }