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 public int getOutputSize(final int len) { return cipherDelegate.getOutputSize(len); }
public int getOutputSize(int len) { return cipher.getOutputSize(len); }
@Override public void close() throws IOException { byte[] output = new byte[cipher.getOutputSize(0)]; try { cipher.doFinal(output, 0); } catch (InvalidCipherTextException e) { // Impossible??? throw new RuntimeException("Impossible: "+e); } out.write(output); out.close(); }
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 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; }
bufLen = aeadBlockCipher.getOutputSize(updateSize);
bufLen = aeadBlockCipher.getOutputSize(updateSize);
bufLen = aeadBlockCipher.getOutputSize(updateSize);
bufLen = aeadBlockCipher.getOutputSize(updateSize);
/** * 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; }
int ciphertextLength = encryptCipher.getOutputSize(plaintextLength);
int plaintextLength = decryptCipher.getOutputSize(ciphertextLength);
/** * 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; }
int ciphertextLength = encryptCipher.getOutputSize(plaintextLength);
int plaintextLength = decryptCipher.getOutputSize(ciphertextLength);