private byte[] encryptOrDecrypt(byte[] key, byte[] contents, boolean forEncryption) { // Credstash uses standard AES BlockCipher engine = new AESFastEngine(); // Credstash uses CTR mode StreamBlockCipher cipher = new SICBlockCipher(engine); cipher.init(forEncryption, new ParametersWithIV(new KeyParameter(key), INITIALIZATION_VECTOR)); byte[] resultBytes = new byte[contents.length]; int contentsOffset = 0; int resultOffset = 0; cipher.processBytes(contents, contentsOffset, contents.length, resultBytes, resultOffset); return resultBytes; }
/** * Create a buffered block cipher that uses Cipher Text Stealing * * @param cipher the underlying block cipher this buffering object wraps. */ public CTSBlockCipher( BlockCipher cipher) { if (cipher instanceof StreamBlockCipher) { throw new IllegalArgumentException("CTSBlockCipher can only accept ECB, or CBC ciphers"); } this.cipher = cipher; blockSize = cipher.getBlockSize(); buf = new byte[blockSize * 2]; bufOff = 0; }
protected JCEStreamCipher( BlockCipher engine, int ivLength) { this.ivLength = ivLength; cipher = new StreamBlockCipher(engine); }
protected BaseStreamCipher( BlockCipher engine, int ivLength) { this.ivLength = ivLength; cipher = new StreamBlockCipher(engine); }
@Override protected StreamCipher createCipher(byte[] iv, boolean encrypt) throws CryptoException { StreamBlockCipher c = getCipher(encrypt); ParametersWithIV parameterIV = new ParametersWithIV(new KeyParameter(mKey), iv, 0, mIVLength); c.init(encrypt, parameterIV); return c; }
protected abstract StreamBlockCipher getCipher(boolean isEncrypted) throws InvalidAlgorithmParameterException;
ChunkDecrypter(StreamBlockCipher cfbAes, GeneralDigest digest) { this.cfbAes = Objects.requireNonNull(cfbAes); this.digest = Objects.requireNonNull(digest); }