Search in sources :

Example 1 with PKCS1Encoding

use of org.bouncycastle.crypto.encodings.PKCS1Encoding in project faf-java-server by FAForever.

the class UniqueIdServiceTest method rsaEncrypt.

private static byte[] rsaEncrypt(byte[] encryptedData, CipherParameters privateKey) throws IOException, InvalidCipherTextException {
    AsymmetricBlockCipher engine = new PKCS1Encoding(new RSAEngine());
    engine.init(true, privateKey);
    return engine.processBlock(encryptedData, 0, encryptedData.length);
}
Also used : PKCS1Encoding(org.bouncycastle.crypto.encodings.PKCS1Encoding) RSAEngine(org.bouncycastle.crypto.engines.RSAEngine) AsymmetricBlockCipher(org.bouncycastle.crypto.AsymmetricBlockCipher)

Example 2 with PKCS1Encoding

use of org.bouncycastle.crypto.encodings.PKCS1Encoding in project 360-Engine-for-Android by 360.

the class RSAEncryptionUtils method rsa.

/**
 * Encrypts or Decrypts bytes with the given RSA Public or Private Key.
 *
 * @param encrypt true for encrypt, false for decrypt.
 * @param key the RSA Public or Private Key.
 * @param data the data to encrypt or decrypt.
 * @return the encrypted or decrypted data.
 */
private static byte[] rsa(final boolean encrypt, final RSAKeyParameters key, final byte[] data) throws InvalidCipherTextException {
    final byte[] dataAligned = new byte[roundUp(data.length, ROUND_UP_VALUE)];
    System.arraycopy(data, 0, dataAligned, 0, data.length);
    final RSAEngine rsa = new RSAEngine();
    final AsymmetricBlockCipher pkcs1 = new PKCS1Encoding(rsa);
    pkcs1.init(encrypt, key);
    if (encrypt)
        return pkcs1.processBlock(dataAligned, 0, dataAligned.length);
    return trimZeros(pkcs1.processBlock(dataAligned, 0, dataAligned.length));
}
Also used : PKCS1Encoding(org.bouncycastle.crypto.encodings.PKCS1Encoding) RSAEngine(org.bouncycastle.crypto.engines.RSAEngine) AsymmetricBlockCipher(org.bouncycastle.crypto.AsymmetricBlockCipher)

Aggregations

AsymmetricBlockCipher (org.bouncycastle.crypto.AsymmetricBlockCipher)2 PKCS1Encoding (org.bouncycastle.crypto.encodings.PKCS1Encoding)2 RSAEngine (org.bouncycastle.crypto.engines.RSAEngine)2