Example usage for org.bouncycastle.crypto.modes AEADBlockCipher getUnderlyingCipher

List of usage examples for org.bouncycastle.crypto.modes AEADBlockCipher getUnderlyingCipher

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.modes AEADBlockCipher getUnderlyingCipher.

Prototype

public BlockCipher getUnderlyingCipher();

Source Link

Document

return the BlockCipher this object wraps.

Usage

From source file:org.cryptacular.util.CipherUtilTest.java

License:Open Source License

@Test(dataProvider = "aead-block-cipher")
public void testAeadBlockCipherEncryptDecrypt(final String plaintext, final AEADBlockCipher cipher) {
    final BlockCipher under = cipher.getUnderlyingCipher();
    final SecretKey key = SecretKeyGenerator.generate(under);
    final byte[] ciphertext = CipherUtil.encrypt(cipher, key, new RBGNonce(12), plaintext.getBytes());
    final byte[] result = CipherUtil.decrypt(cipher, key, ciphertext);
    assertEquals(new String(result), plaintext);
}

From source file:org.cryptacular.util.CipherUtilTest.java

License:Open Source License

@Test(dataProvider = "plaintext-files")
public void testAeadBlockCipherEncryptDecryptStream(final String path) throws Exception {
    final AEADBlockCipher cipher = new GCMBlockCipher(new AESEngine());
    final SecretKey key = SecretKeyGenerator.generate(cipher.getUnderlyingCipher());
    final File file = new File(path);
    final String expected = new String(StreamUtil.readAll(file));
    final ByteArrayOutputStream tempOut = new ByteArrayOutputStream();
    CipherUtil.encrypt(cipher, key, new RBGNonce(), StreamUtil.makeStream(file), tempOut);

    final ByteArrayInputStream tempIn = new ByteArrayInputStream(tempOut.toByteArray());
    final ByteArrayOutputStream actual = new ByteArrayOutputStream();
    CipherUtil.decrypt(cipher, key, tempIn, actual);
    assertEquals(new String(actual.toByteArray()), expected);
}