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; }
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; }
public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) throws DataLengthException { return cipher.processBytes(in, inOff, len, out, outOff); }
@Override public void write(byte[] buf, int offset, int length) throws IOException { byte[] output = new byte[cipher.getUpdateOutputSize(length)]; cipher.processBytes(buf, offset, length, output, 0); out.write(output); }
@Override public int processBytes(final byte[] in, final int inOff, final int len, final byte[] out, final int outOff) throws CryptoException { try { return cipherDelegate.processBytes(in, inOff, len, out, outOff); } catch (RuntimeException e) { throw new CryptoException("Cipher processing error", e); } }
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); } }
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; }
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; }
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; }
@Override protected void _udpEncrypt(byte[] data, ByteArrayOutputStream stream) throws Exception { ByteBuffer buffer = ByteBuffer.wrap(data); int remaining = buffer.remaining(); buffer.get(encBuffer, 0, remaining); encCipher.init(true, getCipherParameters(true)); encCipher.doFinal( encBuffer, encCipher.processBytes(encBuffer, 0, remaining, encBuffer, 0) ); stream.write(encBuffer, 0, remaining + getTagLength()); }
@Override protected void _udpDecrypt(byte[] data, ByteArrayOutputStream stream) throws Exception { ByteBuffer buffer = ByteBuffer.wrap(data); int remaining = buffer.remaining(); buffer.get(decBuffer, 0, remaining); decCipher.init(false, getCipherParameters(false)); decCipher.doFinal( decBuffer, decCipher.processBytes(decBuffer, 0, remaining, decBuffer, 0) ); stream.write(decBuffer, 0, remaining - getTagLength()); } }
int outLen = aeadBlockCipher.processBytes(b, off, len, buf, 0);
int outLen = aeadBlockCipher.processBytes(b, off, len, buf, 0);
encCipher.doFinal( encBuffer, encCipher.processBytes(encBuffer, 0, 2, encBuffer, 0) ); stream.write(encBuffer, 0, 2 + getTagLength()); encCipher.doFinal( encBuffer, 2 + getTagLength() + encCipher.processBytes(encBuffer, 2 + getTagLength(), nr, encBuffer, 2 + getTagLength()) ); increment(this.encNonce);
maxBuf = aeadBlockCipher.processBytes(inBuf, 0, read, buf, 0);
/** * Given the IV, encrypt the provided data * * @param IV initialization vector * @param message data to be encrypted * @return byte array with the cipher text * @throws RuntimeException */ public byte[] encrypt(final byte[] IV, final byte[] message) throws RuntimeException { AEADParameters aeadParams = new AEADParameters( new KeyParameter(key), TAG_LENGTH, IV, authData); cipher.init(true, aeadParams); byte[] cipherText = newBuffer(cipher.getOutputSize(message.length)); int outputOffset = cipher.processBytes(message, 0, message.length, cipherText, 0); try { cipher.doFinal(cipherText, outputOffset); } catch (InvalidCipherTextException e) { throw new RuntimeException("Error: ", e); } return cipherText; }
outputPos += encryptCipher.processBytes(plaintext, plaintextOffset, plaintextLength, output, outputPos); outputPos += encryptCipher.doFinal(output, outputPos);
/** * Given the IV, decrypt the provided data * * @param IV initialization vector * @param cipherText data to be decrypted * @return byte array with the plain text * @throws RuntimeException */ public byte[] decrypt(byte[] IV, byte[] cipherText) throws RuntimeException { AEADParameters aeadParams = new AEADParameters( new KeyParameter(key), TAG_LENGTH, IV, authData); cipher.init(false, aeadParams); byte[] buffer = newByteArray(cipherText); byte[] plainText = newBuffer(cipher.getOutputSize(cipherText.length)); int outputOffset = cipher.processBytes(buffer, 0, buffer.length, plainText, 0); try { cipher.doFinal(plainText, outputOffset); } catch (InvalidCipherTextException e) { throw new RuntimeException("Error: ", e); } return plainText; }
outputPos += decryptCipher.processBytes(ciphertext, ciphertextOffset, ciphertextLength, output, outputPos); outputPos += decryptCipher.doFinal(output, outputPos);
outputPos += encryptCipher.processBytes(plaintext, plaintextOffset, plaintextLength, output, outputPos); outputPos += encryptCipher.doFinal(output, outputPos);