use of org.bouncycastle.crypto.engines.AESFastEngine in project ProxProx by GoMint.
the class EncryptionHandler method createCipher.
private BufferedBlockCipher createCipher(boolean encryptor, byte[] key, byte[] iv) {
BufferedBlockCipher cipher = new BufferedBlockCipher(new CFBBlockCipher(new AESFastEngine(), 8));
cipher.init(encryptor, new ParametersWithIV(new KeyParameter(key), iv));
return cipher;
}
use of org.bouncycastle.crypto.engines.AESFastEngine in project rxlib by RockyLOMO.
the class AesCrypt method getCipher.
@Override
protected StreamBlockCipher getCipher(boolean isEncrypted) throws InvalidAlgorithmParameterException {
AESFastEngine engine = new AESFastEngine();
StreamBlockCipher cipher;
if (_name.equals(CIPHER_AES_128_CFB)) {
cipher = new CFBBlockCipher(engine, getIVLength() * 8);
} else if (_name.equals(CIPHER_AES_192_CFB)) {
cipher = new CFBBlockCipher(engine, getIVLength() * 8);
} else if (_name.equals(CIPHER_AES_256_CFB)) {
cipher = new CFBBlockCipher(engine, getIVLength() * 8);
} else if (_name.equals(CIPHER_AES_128_OFB)) {
cipher = new OFBBlockCipher(engine, getIVLength() * 8);
} else if (_name.equals(CIPHER_AES_192_OFB)) {
cipher = new OFBBlockCipher(engine, getIVLength() * 8);
} else if (_name.equals(CIPHER_AES_256_OFB)) {
cipher = new OFBBlockCipher(engine, getIVLength() * 8);
} else {
throw new InvalidAlgorithmParameterException(_name);
}
return cipher;
}
use of org.bouncycastle.crypto.engines.AESFastEngine in project bitcoin-wallet by bitcoin-wallet.
the class Crypto method encryptRaw.
/**
* Password based encryption using AES - CBC 256 bits.
*
* @param plainTextAsBytes
* The bytes to encrypt
* @param password
* The password to use for encryption
* @return SALT_LENGTH bytes of salt followed by the encrypted bytes.
* @throws IOException
*/
private static byte[] encryptRaw(final byte[] plainTextAsBytes, final char[] password) throws IOException {
try {
// Generate salt - each encryption call has a different salt.
final byte[] salt = new byte[SALT_LENGTH];
secureRandom.nextBytes(salt);
final ParametersWithIV key = (ParametersWithIV) getAESPasswordKey(password, salt);
// The following code uses an AES cipher to encrypt the message.
final BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
cipher.init(true, key);
final byte[] encryptedBytes = new byte[cipher.getOutputSize(plainTextAsBytes.length)];
final int processLen = cipher.processBytes(plainTextAsBytes, 0, plainTextAsBytes.length, encryptedBytes, 0);
final int doFinalLen = cipher.doFinal(encryptedBytes, processLen);
// The result bytes are the SALT_LENGTH bytes followed by the encrypted bytes.
return concat(salt, Arrays.copyOf(encryptedBytes, processLen + doFinalLen));
} catch (final InvalidCipherTextException | DataLengthException x) {
throw new IOException("Could not encrypt bytes", x);
}
}
use of org.bouncycastle.crypto.engines.AESFastEngine 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.engines.AESFastEngine 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);
}
Aggregations