use of org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher in project spring-security by spring-projects.
the class BouncyCastleAesCbcBytesEncryptor method encrypt.
@Override
@SuppressWarnings("deprecation")
public byte[] encrypt(byte[] bytes) {
byte[] iv = this.ivGenerator.generateKey();
PaddedBufferedBlockCipher blockCipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new org.bouncycastle.crypto.engines.AESFastEngine()), new PKCS7Padding());
blockCipher.init(true, new ParametersWithIV(this.secretKey, iv));
byte[] encrypted = process(blockCipher, bytes);
return (iv != null) ? EncodingUtils.concatenate(iv, encrypted) : encrypted;
}
use of org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher in project faf-java-server by FAForever.
the class UniqueIdService method aesDecrypt.
private byte[] aesDecrypt(byte[] initVector, byte[] aesEncryptedJson, byte[] aesKey) throws InvalidCipherTextException {
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
cipher.init(false, new ParametersWithIV(new KeyParameter(aesKey), initVector));
int plaintextSize = cipher.processBytes(aesEncryptedJson, 0, aesEncryptedJson.length, aesEncryptedJson, 0);
plaintextSize += cipher.doFinal(aesEncryptedJson, plaintextSize);
return Arrays.copyOf(aesEncryptedJson, plaintextSize);
}
use of org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher in project faf-java-server by FAForever.
the class UniqueIdServiceTest method aesEncrypt.
private static byte[] aesEncrypt(byte[] initVector, byte[] payload, byte[] aesKey) throws InvalidCipherTextException {
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
cipher.init(true, new ParametersWithIV(new KeyParameter(aesKey), initVector));
byte[] outBuf = new byte[cipher.getOutputSize(payload.length)];
int length = cipher.processBytes(payload, 0, payload.length, outBuf, 0);
length += cipher.doFinal(outBuf, length);
byte[] result = new byte[length];
System.arraycopy(outBuf, 0, result, 0, result.length);
return result;
}
use of org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher in project OsmAnd-tools by osmandapp.
the class SigningUtils method decryptPassphrase.
/**
* Steps (4) to (7): Decrypt passphrase with secret key
* @param pass passphrase from withdrawal request
* @param key secret key
* @return decrypted passphrase for next steps
* @throws BlockIOException
*/
static byte[] decryptPassphrase(byte[] pass, byte[] key) throws BlockIOException {
PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(new AESEngine());
CipherParameters aesKey = new KeyParameter(key);
aes.init(false, aesKey);
try {
return cipherData(aes, pass);
} catch (InvalidCipherTextException e) {
throw new BlockIOException("Unexpected error while signing transaction. Please file an issue report.");
}
}
use of org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher in project OsmAnd-tools by osmandapp.
the class SigningUtils method encryptPassphrase.
/**
* Used only for testing: encrypt secret passphrase
* @param plain plain passphrase
* @param key secret key
* @return encrypted passphrase
* @throws BlockIOException
*/
static byte[] encryptPassphrase(String plain, byte[] key) throws BlockIOException {
PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(new AESEngine());
CipherParameters aesKey = new KeyParameter(key);
aes.init(true, aesKey);
try {
return cipherData(aes, plain.getBytes("UTF-8"));
} catch (InvalidCipherTextException e) {
throw new BlockIOException("Unexpected error while signing transaction. Please file an issue report.");
} catch (UnsupportedEncodingException e) {
throw new BlockIOException("Your system does not seem to support UTF-8 encoding! Aborting signing process.");
}
}
Aggregations