cipher.init(true, new ParametersWithIV(new KeyParameter(K1), IV)); cipher.init(true, new KeyParameter(K1)); C = new byte[cipher.getOutputSize(inLen)]; len = cipher.processBytes(in, inOff, inLen, C, 0); len += cipher.doFinal(C, len);
private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] IV) { AESEngine aesFastEngine = new AESEngine(); EthereumIESEngine iesEngine = new EthereumIESEngine( new ECDHBasicAgreement(), new ConcatKDFBytesGenerator(new SHA256Digest()), new HMac(new SHA256Digest()), new SHA256Digest(), new BufferedBlockCipher(new SICBlockCipher(aesFastEngine))); byte[] d = new byte[] {}; byte[] e = new byte[] {}; IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE); ParametersWithIV parametersWithIV = new ParametersWithIV(p, IV); iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(pub, CURVE), parametersWithIV); return iesEngine; }
/** * Constructs a CipherOutputStream from an OutputStream and a * BufferedBlockCipher. */ public CipherOutputStream( OutputStream os, BufferedBlockCipher cipher) { super(os); this.bufferedBlockCipher = cipher; this.buf = new byte[cipher.getBlockSize()]; }
public byte[] recoverKeyData(int encAlgorithm, byte[] key, byte[] iv, byte[] keyData, int keyOff, int keyLen) throws PGPException { try { BufferedBlockCipher c = BcUtil.createSymmetricKeyWrapper(false, BcImplProvider.createBlockCipher(encAlgorithm), key, iv); byte[] out = new byte[keyLen]; int outLen = c.processBytes(keyData, keyOff, keyLen, out, 0); outLen += c.doFinal(out, outLen); return out; } catch (InvalidCipherTextException e) { throw new PGPException("decryption failed: " + e.getMessage(), e); } } };
private static byte[] cipherData(BufferedBlockCipher cipher, byte[] data) { int minSize = cipher.getOutputSize(data.length); byte[] outBuf = new byte[minSize]; int len1 = cipher.processBytes(data, 0, data.length, outBuf, 0); int len2 = -1; try { len2 = cipher.doFinal(outBuf, len1); } catch (InvalidCipherTextException icte) { icte.printStackTrace(); } int actualLength = len1 + len2; byte[] result = new byte[actualLength]; System.arraycopy(outBuf, 0, result, 0, result.length); return result; }
protected int engineUpdate( byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) { return cipher.processBytes(input, inputOffset, inputLen, output, outputOffset); }
byte[] buf = new byte[bufferedBlockCipher.getOutputSize(len)]; int outLen = bufferedBlockCipher.processBytes(b, off, len, buf, 0);
static BufferedBlockCipher createStreamCipher(boolean forEncryption, BlockCipher engine, boolean withIntegrityPacket, byte[] key) { BufferedBlockCipher c; if (withIntegrityPacket) { c = new BufferedBlockCipher(new CFBBlockCipher(engine, engine.getBlockSize() * 8)); } else { c = new BufferedBlockCipher(new OpenPGPCFBBlockCipher(engine)); } KeyParameter keyParameter = new KeyParameter(key); if (withIntegrityPacket) { c.init(forEncryption, new ParametersWithIV(keyParameter, new byte[engine.getBlockSize()])); } else { c.init(forEncryption, keyParameter); } return c; }
protected int engineGetOutputSize( int inputLen) { return cipher.getOutputSize(inputLen); }
CipherParameters params = PKCS12PBEUtils.createCipherParameters(algorithm, digest, engine.getBlockSize(), pbeParams, password); engine.init(true, params);
public void init(boolean forEncryption, CipherParameters params) throws IllegalArgumentException { cipher.init(forEncryption, params); }
public int doFinal(byte[] out, int outOff) throws IllegalStateException, InvalidCipherTextException { return cipher.doFinal(out, outOff); } }
protected byte[] engineUpdate( byte[] input, int inputOffset, int inputLen) { int length = cipher.getUpdateOutputSize(inputLen); if (length > 0) { byte[] out = new byte[length]; cipher.processBytes(input, inputOffset, inputLen, out, 0); return out; } cipher.processBytes(input, inputOffset, inputLen, null, 0); return null; }
/** * * @param key AES key (256 bit Buffer) * @param data e.g. "{'aaa':'bbb'}" * @return * @throws InvalidCipherTextException */ public static byte[] encryptWithKey(byte[] key, String data) throws InvalidCipherTextException, UnsupportedEncodingException { byte[] iv = getSalt(); byte[] dataBytes = data.getBytes("utf-8"); KeyParameter keyParam = new KeyParameter(key); CipherParameters params = new ParametersWithIV(keyParam, iv); BlockCipher cipherMode = new CBCBlockCipher(new AESFastEngine()); BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(cipherMode, new ISO10126d2Padding()); cipher.reset(); cipher.init(true, params); byte[] outBuf = cipherData(cipher, dataBytes); // Concatenate iv int len1 = iv.length; int len2 = outBuf.length; byte[] ivAppended = new byte[len1 + len2]; System.arraycopy(iv, 0, ivAppended, 0, len1); System.arraycopy(outBuf, 0, ivAppended, len1, len2); return Base64.encodeBase64(ivAppended); }
int blockSize = getBlockSize(); int length = getUpdateOutputSize(len);
cipher = new PaddedBufferedBlockCipher(cipher.getUnderlyingCipher()); ivLength = cipher.getUnderlyingCipher().getBlockSize(); cipher = new PaddedBufferedBlockCipher( new CBCBlockCipher(cipher.getUnderlyingCipher())); ivLength = cipher.getUnderlyingCipher().getBlockSize(); if (modeName.length() != 3) new OFBBlockCipher(cipher.getUnderlyingCipher(), wordSize)); new OFBBlockCipher(cipher.getUnderlyingCipher(), 8 * cipher.getBlockSize())); ivLength = cipher.getUnderlyingCipher().getBlockSize(); if (modeName.length() != 3) new CFBBlockCipher(cipher.getUnderlyingCipher(), wordSize)); new CFBBlockCipher(cipher.getUnderlyingCipher(), 8 * cipher.getBlockSize()));
public byte[] recoverSessionData(int keyAlgorithm, byte[] key, byte[] secKeyData) throws PGPException { try { if (secKeyData != null && secKeyData.length > 0) { BlockCipher engine = BcImplProvider.createBlockCipher(keyAlgorithm); BufferedBlockCipher cipher = BcUtil.createSymmetricKeyWrapper(false, engine, key, new byte[engine.getBlockSize()]); byte[] out = new byte[secKeyData.length]; int len = cipher.processBytes(secKeyData, 0, secKeyData.length, out, 0); len += cipher.doFinal(out, len); return out; } else { byte[] keyBytes = new byte[key.length + 1]; keyBytes[0] = (byte)keyAlgorithm; System.arraycopy(key, 0, keyBytes, 1, key.length); return keyBytes; } } catch (Exception e) { throw new PGPException("Exception recovering session info", e); } }
protected int engineUpdate( byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) { return cipher.processBytes(input, inputOffset, inputLen, output, outputOffset); }
public static BufferedBlockCipher createSymmetricKeyWrapper(boolean forEncryption, BlockCipher engine, byte[] key, byte[] iv) { BufferedBlockCipher c = new BufferedBlockCipher(new CFBBlockCipher(engine, engine.getBlockSize() * 8)); c.init(forEncryption, new ParametersWithIV(new KeyParameter(key), iv)); return c; }
protected int engineGetOutputSize( int inputLen) { return cipher.getOutputSize(inputLen); }