private static String encrypt(byte[] key, String plainText) throws CryptoException { try { PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new DESEngine())); KeyParameter keyParameter = new KeyParameter(key); cipher.init(true, keyParameter); byte[] plainTextBytes = plainText.getBytes(); byte[] cipherTextBytes = new byte[cipher.getOutputSize(plainTextBytes.length)]; int outputLength = cipher.processBytes(plainTextBytes, 0, plainTextBytes.length, cipherTextBytes, 0); cipher.doFinal(cipherTextBytes, outputLength); return ENCODER.encodeToString(cipherTextBytes).trim(); } catch (Exception e) { throw new CryptoException(e); } }
engine.init(true, param); int blockSize = engine.getBlockSize(); byte[] cekBlock; engine.processBlock(cekBlock, i, cekBlock, i); engine.processBlock(cekBlock, i, cekBlock, i);
/** * Process one block of input from the array in and write it to * the out array. * * @param in the array containing the input data. * @param inOff offset into the in array the data starts at. * @param out the array the output data will be copied into. * @param outOff the offset into the out array the output will start at. * @exception DataLengthException if there isn't enough data in in, or * space in out. * @exception IllegalStateException if the cipher isn't initialised. * @return the number of bytes processed and produced. */ public int processBlock( byte[] in, int inOff, byte[] out, int outOff) throws DataLengthException, IllegalStateException { return (encrypting) ? encryptBlock(in, inOff, out, outOff) : decryptBlock(in, inOff, out, outOff); }
engine.init(true, param); int blockSize = engine.getBlockSize(); byte[] cekBlock; engine.processBlock(cekBlock, i, cekBlock, i); engine.processBlock(cekBlock, i, cekBlock, i);
/** * Process one block of input from the array in and write it to * the out array. * * @param in the array containing the input data. * @param inOff offset into the in array the data starts at. * @param out the array the output data will be copied into. * @param outOff the offset into the out array the output will start at. * @exception DataLengthException if there isn't enough data in in, or * space in out. * @exception IllegalStateException if the cipher isn't initialised. * @return the number of bytes processed and produced. */ public int processBlock( byte[] in, int inOff, byte[] out, int outOff) throws DataLengthException, IllegalStateException { return (encrypting) ? encryptBlock(in, inOff, out, outOff) : decryptBlock(in, inOff, out, outOff); }
private static String decrypt(byte[] key, String cipherText) throws CryptoException { try { PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new DESEngine())); cipher.init(false, new KeyParameter(key)); byte[] cipherTextBytes = DECODER.decode(cipherText); byte[] plainTextBytes = new byte[cipher.getOutputSize(cipherTextBytes.length)]; int outputLength = cipher.processBytes(cipherTextBytes, 0, cipherTextBytes.length, plainTextBytes, 0); cipher.doFinal(plainTextBytes, outputLength); int paddingStarts = plainTextBytes.length - 1; for (; paddingStarts >= 0; paddingStarts--) { if (plainTextBytes[paddingStarts] != 0) { break; } } return new String(plainTextBytes, 0, paddingStarts + 1); } catch (Exception e) { throw new CryptoException(e); } }
int noOfBlocks = WKCKS.length / engine.getBlockSize(); int extraBytes = WKCKS.length % engine.getBlockSize(); engine.init(true, paramPlusIV); int currentBytePos = i * engine.getBlockSize(); engine.processBlock(TEMP1, currentBytePos, TEMP1, currentBytePos); this.engine.init(true, param2); int currentBytePos = i * engine.getBlockSize(); engine.processBlock(TEMP3, currentBytePos, TEMP3, currentBytePos);
@Override public byte[] encrypt(byte[] bytes) { byte[] iv = this.ivGenerator.generateKey(); @SuppressWarnings("deprecation") PaddedBufferedBlockCipher blockCipher = new PaddedBufferedBlockCipher( new CBCBlockCipher(new org.bouncycastle.crypto.engines.AESFastEngine()), new PKCS7Padding()); blockCipher.init(true, new ParametersWithIV(secretKey, iv)); byte[] encrypted = process(blockCipher, bytes); return iv != null ? concatenate(iv, encrypted) : encrypted; }
int noOfBlocks = WKCKS.length / engine.getBlockSize(); int extraBytes = WKCKS.length % engine.getBlockSize(); engine.init(true, paramPlusIV); int currentBytePos = i * engine.getBlockSize(); engine.processBlock(TEMP1, currentBytePos, TEMP1, currentBytePos); this.engine.init(true, param2); int currentBytePos = i * engine.getBlockSize(); engine.processBlock(TEMP3, currentBytePos, TEMP3, currentBytePos);
@Override public byte[] encrypt(byte[] bytes) { byte[] iv = this.ivGenerator.generateKey(); @SuppressWarnings("deprecation") PaddedBufferedBlockCipher blockCipher = new PaddedBufferedBlockCipher( new CBCBlockCipher(new org.bouncycastle.crypto.engines.AESFastEngine()), new PKCS7Padding()); blockCipher.init(true, new ParametersWithIV(secretKey, iv)); byte[] encrypted = process(blockCipher, bytes); return iv != null ? concatenate(iv, encrypted) : encrypted; }
int blockSize = engine.getBlockSize(); engine.init(true, paramPlusIV); engine.processBlock(WKCKS, currentBytePos, TEMP1, currentBytePos); this.engine.init(true, param2); engine.processBlock(TEMP3, currentBytePos, TEMP3, currentBytePos);
@Override public byte[] decrypt(byte[] encryptedBytes) { byte[] iv = subArray(encryptedBytes, 0, this.ivGenerator.getKeyLength()); encryptedBytes = subArray(encryptedBytes, this.ivGenerator.getKeyLength(), encryptedBytes.length); @SuppressWarnings("deprecation") PaddedBufferedBlockCipher blockCipher = new PaddedBufferedBlockCipher( new CBCBlockCipher(new org.bouncycastle.crypto.engines.AESFastEngine()), new PKCS7Padding()); blockCipher.init(false, new ParametersWithIV(secretKey, iv)); return process(blockCipher, encryptedBytes); }
int blockSize = engine.getBlockSize(); engine.init(true, paramPlusIV); engine.processBlock(WKCKS, currentBytePos, TEMP1, currentBytePos); this.engine.init(true, param2); engine.processBlock(TEMP3, currentBytePos, TEMP3, currentBytePos);
@Override public byte[] decrypt(byte[] encryptedBytes) { byte[] iv = subArray(encryptedBytes, 0, this.ivGenerator.getKeyLength()); encryptedBytes = subArray(encryptedBytes, this.ivGenerator.getKeyLength(), encryptedBytes.length); @SuppressWarnings("deprecation") PaddedBufferedBlockCipher blockCipher = new PaddedBufferedBlockCipher( new CBCBlockCipher(new org.bouncycastle.crypto.engines.AESFastEngine()), new PKCS7Padding()); blockCipher.init(false, new ParametersWithIV(secretKey, iv)); return process(blockCipher, encryptedBytes); }
int blockSize = engine.getBlockSize(); System.arraycopy(in, inOff, iv, 0, iv.length); engine.init(false, new ParametersWithIV(param.getParameters(), iv)); engine.processBlock(cekBlock, i, cekBlock, i); engine.init(false, new ParametersWithIV(param.getParameters(), iv)); engine.processBlock(cekBlock, 0, cekBlock, 0); engine.init(false, param); engine.processBlock(cekBlock, i, cekBlock, i);
public RFC3211WrapEngine(BlockCipher engine) { this.engine = new CBCBlockCipher(engine); }
int blockSize = engine.getBlockSize(); System.arraycopy(in, inOff, iv, 0, iv.length); engine.init(false, new ParametersWithIV(param.getParameters(), iv)); engine.processBlock(cekBlock, i, cekBlock, i); engine.init(false, new ParametersWithIV(param.getParameters(), iv)); engine.processBlock(cekBlock, 0, cekBlock, 0); engine.init(false, param); engine.processBlock(cekBlock, i, cekBlock, i);
public RFC3211WrapEngine(BlockCipher engine) { this.engine = new CBCBlockCipher(engine); }
if (inLen % engine.getBlockSize() != 0) + engine.getBlockSize()); this.engine.init(false, param2); for (int i = 0; i < (TEMP3.length / engine.getBlockSize()); i++) int currentBytePos = i * engine.getBlockSize(); engine.processBlock(TEMP3, currentBytePos, TEMP3, currentBytePos); this.engine.init(false, this.paramPlusIV); for (int i = 0; i < (LCEKPADICV.length / engine.getBlockSize()); i++) int currentBytePos = i * engine.getBlockSize(); engine.processBlock(LCEKPADICV, currentBytePos, LCEKPADICV, currentBytePos);
protected BlockCipher createAESBlockCipher() { return new CBCBlockCipher(createAESEngine()); }