本文整理汇总了Java中org.bouncycastle.crypto.params.CramerShoupParameters类的典型用法代码示例。如果您正苦于以下问题:Java CramerShoupParameters类的具体用法?Java CramerShoupParameters怎么用?Java CramerShoupParameters使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CramerShoupParameters类属于org.bouncycastle.crypto.params包,在下文中一共展示了CramerShoupParameters类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateParameters
import org.bouncycastle.crypto.params.CramerShoupParameters; //导入依赖的package包/类
/**
* which generates the p and g values from the given parameters, returning
* the CramerShoupParameters object.
* <p>
* Note: can take a while...
* </p>
*/
public CramerShoupParameters generateParameters()
{
//
// find a safe prime p where p = 2*q + 1, where p and q are prime.
//
BigInteger[] safePrimes = ParametersHelper.generateSafePrimes(size, certainty, random);
// BigInteger p = safePrimes[0];
BigInteger q = safePrimes[1];
BigInteger g1 = ParametersHelper.selectGenerator(q, random);
BigInteger g2 = ParametersHelper.selectGenerator(q, random);
while (g1.equals(g2))
{
g2 = ParametersHelper.selectGenerator(q, random);
}
return new CramerShoupParameters(q, g1, g2, new SHA256Digest());
}
示例2: encrypt
import org.bouncycastle.crypto.params.CramerShoupParameters; //导入依赖的package包/类
private CramerShoupCiphertext encrypt(BigInteger message, String label)
{
CramerShoupKeyPairGenerator kpGen = new CramerShoupKeyPairGenerator();
CramerShoupParametersGenerator pGen = new CramerShoupParametersGenerator();
pGen.init(2048, 1, RND);
CramerShoupParameters params = pGen.generateParameters(DHStandardGroups.rfc3526_2048);
CramerShoupKeyGenerationParameters param = new CramerShoupKeyGenerationParameters(RND, params);
kpGen.init(param);
keyPair = kpGen.generateKeyPair();
CramerShoupCoreEngine engine = new CramerShoupCoreEngine();
if (label != null)
{
engine.init(true, keyPair.getPublic(), label);
}
else
{
engine.init(true, keyPair.getPublic());
}
CramerShoupCiphertext ciphertext = engine.encryptBlock(message);
return ciphertext;
}
示例3: generateKeyPair
import org.bouncycastle.crypto.params.CramerShoupParameters; //导入依赖的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);
}
示例4: generatePrivateKey
import org.bouncycastle.crypto.params.CramerShoupParameters; //导入依赖的package包/类
private CramerShoupPrivateKeyParameters generatePrivateKey(SecureRandom random, CramerShoupParameters csParams){
BigInteger p = csParams.getP();
CramerShoupPrivateKeyParameters key = new CramerShoupPrivateKeyParameters(csParams,
generateRandomElement(p, random), generateRandomElement(p, random),
generateRandomElement(p, random), generateRandomElement(p, random),
generateRandomElement(p, random));
return key;
}
示例5: calculatePublicKey
import org.bouncycastle.crypto.params.CramerShoupParameters; //导入依赖的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);
}