Java Code Examples for org.bouncycastle.crypto.modes.AEADBlockCipher#processBytes()

The following examples show how to use org.bouncycastle.crypto.modes.AEADBlockCipher#processBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AESGCMBytesEncryptor.java    From flair-engine with Apache License 2.0 5 votes vote down vote up
private byte[] process(AEADBlockCipher blockCipher, byte[] in) {
    byte[] buf = new byte[blockCipher.getOutputSize(in.length)];
    int bytesWritten = blockCipher.processBytes(in, 0, in.length, buf, 0);
    try {
        bytesWritten += blockCipher.doFinal(buf, bytesWritten);
    } catch (InvalidCipherTextException e) {
        throw new IllegalStateException("unable to encrypt/decrypt", e);
    }
    if (bytesWritten == buf.length) {
        return buf;
    }
    byte[] out = new byte[bytesWritten];
    System.arraycopy(buf, 0, out, 0, bytesWritten);
    return out;
}
 
Example 2
Source File: AESGCMEncryptor.java    From archistar-smc with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static byte[] cipherData(AEADBlockCipher cipher, byte[] data) throws IllegalStateException, InvalidCipherTextException {
    int minSize = cipher.getOutputSize(data.length);
    byte[] outBuf = new byte[minSize];
    int length1 = cipher.processBytes(data, 0, data.length, outBuf, 0);
    int length2 = cipher.doFinal(outBuf, length1);
    int actualLength = length1 + length2;
    if (actualLength == minSize) {
        return outBuf;
    } else {
        return Arrays.copyOf(outBuf, actualLength);
    }
}