Search in sources :

Example 1 with NativeGCMCipherOutputStream

use of com.facebook.crypto.streams.NativeGCMCipherOutputStream in project conceal by facebook.

the class NativeGCMCipherHelper method getOutputStream.

public OutputStream getOutputStream(OutputStream cipherStream, byte[] encryptBuffer) throws IOException, CryptoInitializationException {
    NativeGCMCipher gcmCipher = new NativeGCMCipher(mNativeCryptoLibrary);
    gcmCipher.encryptInit(mKey, mIv);
    cipherStream.write(mIv);
    return new NativeGCMCipherOutputStream(cipherStream, gcmCipher, encryptBuffer, mTagLength);
}
Also used : NativeGCMCipherOutputStream(com.facebook.crypto.streams.NativeGCMCipherOutputStream) NativeGCMCipher(com.facebook.crypto.cipher.NativeGCMCipher)

Example 2 with NativeGCMCipherOutputStream

use of com.facebook.crypto.streams.NativeGCMCipherOutputStream in project conceal by facebook.

the class CryptoAlgoGcm method wrap.

@Override
public OutputStream wrap(OutputStream cipherStream, Entity entity, byte[] buffer) throws IOException, CryptoInitializationException, KeyChainException {
    cipherStream.write(VersionCodes.CIPHER_SERIALIZATION_VERSION);
    cipherStream.write(mConfig.cipherId);
    byte[] iv = mKeyChain.getNewIV();
    NativeGCMCipher gcmCipher = new NativeGCMCipher(mNativeLibrary);
    gcmCipher.encryptInit(mKeyChain.getCipherKey(), iv);
    cipherStream.write(iv);
    byte[] entityBytes = entity.getBytes();
    computeCipherAad(gcmCipher, VersionCodes.CIPHER_SERIALIZATION_VERSION, mConfig.cipherId, entityBytes);
    return new NativeGCMCipherOutputStream(cipherStream, gcmCipher, buffer, mConfig.tagLength);
}
Also used : NativeGCMCipherOutputStream(com.facebook.crypto.streams.NativeGCMCipherOutputStream) NativeGCMCipher(com.facebook.crypto.cipher.NativeGCMCipher)

Aggregations

NativeGCMCipher (com.facebook.crypto.cipher.NativeGCMCipher)2 NativeGCMCipherOutputStream (com.facebook.crypto.streams.NativeGCMCipherOutputStream)2