use of org.bouncycastle.crypto.AsymmetricBlockCipher 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);
}
use of org.bouncycastle.crypto.AsymmetricBlockCipher in project xipki by xipki.
the class SignerUtil method createPSSRSASigner.
// CHECKSTYLE:SKIP
public static PSSSigner createPSSRSASigner(AlgorithmIdentifier sigAlgId, AsymmetricBlockCipher cipher) throws XiSecurityException {
ParamUtil.requireNonNull("sigAlgId", sigAlgId);
if (!PKCSObjectIdentifiers.id_RSASSA_PSS.equals(sigAlgId.getAlgorithm())) {
throw new XiSecurityException("signature algorithm " + sigAlgId.getAlgorithm() + " is not allowed");
}
AlgorithmIdentifier digAlgId;
try {
digAlgId = AlgorithmUtil.extractDigesetAlgFromSigAlg(sigAlgId);
} catch (NoSuchAlgorithmException ex) {
throw new XiSecurityException(ex.getMessage(), ex);
}
RSASSAPSSparams param = RSASSAPSSparams.getInstance(sigAlgId.getParameters());
AlgorithmIdentifier mfgDigAlgId = AlgorithmIdentifier.getInstance(param.getMaskGenAlgorithm().getParameters());
Digest dig = getDigest(digAlgId);
Digest mfgDig = getDigest(mfgDigAlgId);
int saltSize = param.getSaltLength().intValue();
int trailerField = param.getTrailerField().intValue();
AsymmetricBlockCipher tmpCipher = (cipher == null) ? new RSABlindedEngine() : cipher;
return new PSSSigner(tmpCipher, dig, mfgDig, saltSize, getTrailer(trailerField));
}
use of org.bouncycastle.crypto.AsymmetricBlockCipher 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));
}
Aggregations