List of usage examples for org.bouncycastle.crypto StreamBlockCipher processBytes
public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) throws DataLengthException
From source file:com.github.horrorho.inflatabledonkey.chunk.engine.ChunkDecrypters.java
License:Open Source License
public static Optional<byte[]> decrypt(byte[] key, StreamBlockCipher cipher, byte[] data, int offset, int length) { try {/*from www . ja v a 2s . c o m*/ KeyParameter keyParameter = new KeyParameter(key); cipher.init(false, keyParameter); byte[] decrypted = new byte[length]; cipher.processBytes(data, offset, length, decrypted, 0); return Optional.of(decrypted); } catch (DataLengthException ex) { logger.warn("-- decrypt() - exception: ", ex); return Optional.empty(); } }
From source file:shadowsocks.crypto.AESCrypto.java
License:Apache License
@Override protected void process(byte[] in, ByteArrayOutputStream out, boolean encrypt) { int size;/*from w w w. j a v a 2 s. c o m*/ byte[] buffer = new byte[in.length]; StreamBlockCipher cipher; if (encrypt) { cipher = (StreamBlockCipher) mEncryptCipher; } else { cipher = (StreamBlockCipher) mDecryptCipher; } size = cipher.processBytes(in, 0, in.length, buffer, 0); out.write(buffer, 0, size); }