本文整理匯總了Java中org.bouncycastle.crypto.params.CramerShoupPublicKeyParameters類的典型用法代碼示例。如果您正苦於以下問題:Java CramerShoupPublicKeyParameters類的具體用法?Java CramerShoupPublicKeyParameters怎麽用?Java CramerShoupPublicKeyParameters使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CramerShoupPublicKeyParameters類屬於org.bouncycastle.crypto.params包,在下文中一共展示了CramerShoupPublicKeyParameters類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generateKeyPair
import org.bouncycastle.crypto.params.CramerShoupPublicKeyParameters; //導入依賴的package包/類
public AsymmetricCipherKeyPair generateKeyPair() {
CramerShoupParameters csParams = param.getParameters();
CramerShoupPrivateKeyParameters sk = generatePrivateKey(param.getRandom(), csParams);
CramerShoupPublicKeyParameters pk = calculatePublicKey(csParams, sk);
sk.setPk(pk);
return new AsymmetricCipherKeyPair(pk, sk);
}
示例2: calculatePublicKey
import org.bouncycastle.crypto.params.CramerShoupPublicKeyParameters; //導入依賴的package包/類
private CramerShoupPublicKeyParameters calculatePublicKey(CramerShoupParameters csParams, CramerShoupPrivateKeyParameters sk) {
BigInteger g1 = csParams.getG1();
BigInteger g2 = csParams.getG2();
BigInteger p = csParams.getP();
BigInteger c = g1.modPow(sk.getX1(), p).multiply(g2.modPow(sk.getX2(), p));
BigInteger d = g1.modPow(sk.getY1(), p).multiply(g2.modPow(sk.getY2(), p));
BigInteger h = g1.modPow(sk.getZ(), p);
return new CramerShoupPublicKeyParameters(csParams, c, d, h);
}
示例3: encryptBlock
import org.bouncycastle.crypto.params.CramerShoupPublicKeyParameters; //導入依賴的package包/類
public CramerShoupCiphertext encryptBlock(BigInteger input)
{
CramerShoupCiphertext result = null;
if (!key.isPrivate() && this.forEncryption && key instanceof CramerShoupPublicKeyParameters)
{
CramerShoupPublicKeyParameters pk = (CramerShoupPublicKeyParameters)key;
BigInteger p = pk.getParameters().getP();
BigInteger g1 = pk.getParameters().getG1();
BigInteger g2 = pk.getParameters().getG2();
BigInteger h = pk.getH();
if (!isValidMessage(input, p))
{
return result;
}
BigInteger r = generateRandomElement(p, random);
BigInteger u1, u2, v, e, a;
u1 = g1.modPow(r, p);
u2 = g2.modPow(r, p);
e = h.modPow(r, p).multiply(input).mod(p);
Digest digest = pk.getParameters().getH();
byte[] u1Bytes = u1.toByteArray();
digest.update(u1Bytes, 0, u1Bytes.length);
byte[] u2Bytes = u2.toByteArray();
digest.update(u2Bytes, 0, u2Bytes.length);
byte[] eBytes = e.toByteArray();
digest.update(eBytes, 0, eBytes.length);
if (this.label != null)
{
byte[] lBytes = this.label.getBytes();
digest.update(lBytes, 0, lBytes.length);
}
byte[] out = new byte[digest.getDigestSize()];
digest.doFinal(out, 0);
a = new BigInteger(1, out);
v = pk.getC().modPow(r, p).multiply(pk.getD().modPow(r.multiply(a), p)).mod(p);
result = new CramerShoupCiphertext(u1, u2, e, v);
}
return result;
}