use of org.bouncycastle.crypto.params.ParametersWithRandom in project robovm by robovm.
the class SignatureSpi method engineInitSign.
protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
CipherParameters param = ECUtil.generatePrivateKeyParameter(privateKey);
digest.reset();
if (appRandom != null) {
signer.init(true, new ParametersWithRandom(param, appRandom));
} else {
signer.init(true, param);
}
}
use of org.bouncycastle.crypto.params.ParametersWithRandom in project xipki by xipki.
the class P11RSAPSSSignatureSpi method engineInitSign.
protected void engineInitSign(PrivateKey privateKey, SecureRandom random) throws InvalidKeyException {
if (!(privateKey instanceof P11PrivateKey)) {
throw new InvalidKeyException("privateKey is not instanceof " + P11PrivateKey.class.getName());
}
String algo = privateKey.getAlgorithm();
if (!"RSA".equals(algo)) {
throw new InvalidKeyException("privateKey is not an RSA private key: " + algo);
}
this.signingKey = (P11PrivateKey) privateKey;
pss = new org.bouncycastle.crypto.signers.PSSSigner(signer, contentDigest, mgfDigest, saltLength, trailer);
P11RSAKeyParameter p11KeyParam = P11RSAKeyParameter.getInstance(signingKey.getP11CryptService(), signingKey.getIdentityId());
if (random == null) {
pss.init(true, p11KeyParam);
} else {
pss.init(true, new ParametersWithRandom(p11KeyParam, random));
}
}
use of org.bouncycastle.crypto.params.ParametersWithRandom in project web3sdk by FISCO-BCOS.
the class SM2Sign method sign2.
/**
* The new sm2 signature algorithm with better performance
*
* @param message
* @param ecKeyPair
* @return
*/
public static Sign.SignatureData sign2(byte[] message, ECKeyPair ecKeyPair) {
SM2Signer sm2Signer = new SM2Signer();
ECPrivateKeyParameters eCPrivateKeyParameters = new ECPrivateKeyParameters(ecKeyPair.getPrivateKey(), eCDomainParameters);
sm2Signer.initWithCache(true, new ParametersWithID(new ParametersWithRandom(eCPrivateKeyParameters), identValue));
org.bouncycastle.crypto.digests.SM3Digest sm3Digest = new org.bouncycastle.crypto.digests.SM3Digest();
byte[] md = new byte[sm3Digest.getDigestSize()];
sm3Digest.update(message, 0, message.length);
sm3Digest.doFinal(md, 0);
sm2Signer.update(md, 0, md.length);
byte[] r = null;
byte[] s = null;
byte[] pub = null;
try {
BigInteger[] bigIntegers = sm2Signer.generateSignature2();
pub = Numeric.toBytesPadded(ecKeyPair.getPublicKey(), 64);
r = SM2Algorithm.getEncoded(bigIntegers[0]);
s = SM2Algorithm.getEncoded(bigIntegers[1]);
} catch (CryptoException e) {
throw new RuntimeException(e);
}
return new Sign.SignatureData((byte) 0, r, s, pub);
}
use of org.bouncycastle.crypto.params.ParametersWithRandom in project 360-Engine-for-Android by 360.
the class RSACoreEngine method init.
/**
* initialise the RSA engine.
*
* @param forEncryption true if we are encrypting, false otherwise.
* @param param the necessary RSA key parameters.
*/
public void init(boolean forEncryption, CipherParameters param) {
if (param instanceof ParametersWithRandom) {
ParametersWithRandom rParam = (ParametersWithRandom) param;
key = (RSAKeyParameters) rParam.getParameters();
} else {
key = (RSAKeyParameters) param;
}
this.forEncryption = forEncryption;
}
use of org.bouncycastle.crypto.params.ParametersWithRandom in project Skein3Fish by wernerd.
the class DSASigner method init.
public void init(boolean forSigning, CipherParameters param) {
if (forSigning) {
if (param instanceof ParametersWithRandom) {
ParametersWithRandom rParam = (ParametersWithRandom) param;
this.random = rParam.getRandom();
this.key = (DSAPrivateKeyParameters) rParam.getParameters();
} else {
this.random = new SecureRandom();
this.key = (DSAPrivateKeyParameters) param;
}
} else {
this.key = (DSAPublicKeyParameters) param;
}
}
Aggregations