• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ElGamalKeyGenerationParameters类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.bouncycastle.crypto.params.ElGamalKeyGenerationParameters的典型用法代码示例。如果您正苦于以下问题:Java ElGamalKeyGenerationParameters类的具体用法?Java ElGamalKeyGenerationParameters怎么用?Java ElGamalKeyGenerationParameters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ElGamalKeyGenerationParameters类属于org.bouncycastle.crypto.params包,在下文中一共展示了ElGamalKeyGenerationParameters类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createAsymmetricCipherKeyPairGenerator

import org.bouncycastle.crypto.params.ElGamalKeyGenerationParameters; //导入依赖的package包/类
@Override
public AsymmetricCipherKeyPairGenerator createAsymmetricCipherKeyPairGenerator(final boolean initWithDefaults) {
	final ElGamalKeyPairGenerator generator = new ElGamalKeyPairGenerator();

	if (initWithDefaults) {
		/*
		 * How certain do we want to be that the chosen primes are really primes.
		 * <p>
		 * The higher this number, the more tests are done to make sure they are primes (and not composites).
		 * <p>
		 * See: <a href="http://crypto.stackexchange.com/questions/3114/what-is-the-correct-value-for-certainty-in-rsa-key-pair-generation">What is the correct value for “certainty” in RSA key pair generation?</a>
		 * and
		 * <a href="http://crypto.stackexchange.com/questions/3126/does-a-high-exponent-compensate-for-a-low-degree-of-certainty?lq=1">Does a high exponent compensate for a low degree of certainty?</a>
		 */
		final int certainty = 12;

		final SecureRandom random = new SecureRandom();

		ElGamalParametersGenerator pGen = new ElGamalParametersGenerator();
		pGen.init(4096, certainty, random);
		ElGamalParameters elGamalParameters = pGen.generateParameters();
		generator.init(new ElGamalKeyGenerationParameters(random, elGamalParameters));
	}
	return generator;
}
 
开发者ID:subshare,项目名称:subshare,代码行数:26,代码来源:ElGamalKeyPairGeneratorFactory.java


示例2: createElGamalKeyGenerationParameters

import org.bouncycastle.crypto.params.ElGamalKeyGenerationParameters; //导入依赖的package包/类
private ElGamalKeyGenerationParameters createElGamalKeyGenerationParameters(final CreatePgpKeyParam createPgpKeyParam) {
	/*
	 * How certain do we want to be that the chosen primes are really primes.
	 * <p>
	 * The higher this number, the more tests are done to make sure they are primes (and not composites).
	 * <p>
	 * See: <a href="http://crypto.stackexchange.com/questions/3114/what-is-the-correct-value-for-certainty-in-rsa-key-pair-generation">What is the correct value for “certainty” in RSA key pair generation?</a>
	 * and
	 * <a href="http://crypto.stackexchange.com/questions/3126/does-a-high-exponent-compensate-for-a-low-degree-of-certainty?lq=1">Does a high exponent compensate for a low degree of certainty?</a>
	 */
	final int certainty = 8; // 12 takes ages - and DSA+El-Gamal is anyway a bad idea and discouraged. Reducing this to make it bearable.

	final SecureRandom random = getSecureRandom();

	ElGamalParametersGenerator pGen = new ElGamalParametersGenerator();
	pGen.init(createPgpKeyParam.getStrength(), certainty, random);
	ElGamalParameters elGamalParameters = pGen.generateParameters();

	// Maybe we should generate our "DH safe primes" only once and store them somewhere? Or maybe we should provide a long list
	// of them in the resources? DHParametersHelper.generateSafePrimes(size, certainty, random); takes really really very long.
	// BUT BEWARE: Attacks on El Gamal can re-use expensively calculated stuff, if p (one of the "safe primes) is the same.
	// However, it is still not *so* easy. Hmmm... don't know. Security is really important here.

	return new ElGamalKeyGenerationParameters(random, elGamalParameters);
}
 
开发者ID:subshare,项目名称:subshare,代码行数:26,代码来源:BcWithLocalGnuPgPgp.java


示例3: GenerateKeys

import org.bouncycastle.crypto.params.ElGamalKeyGenerationParameters; //导入依赖的package包/类
/**
 * This method is used to generate Public Key and Private Key
 * @param params
 */
private void GenerateKeys(ElGamalParameters params, String password){
	ElGamalKeyGenerationParameters elGP = new ElGamalKeyGenerationParameters(random,params);
	ElGamalKeyPairGenerator KeyPair = new ElGamalKeyPairGenerator();
	KeyPair.init(elGP);
	AsymmetricCipherKeyPair cipher1 = KeyPair.generateKeyPair();
	publicKey = ((ElGamalPublicKeyParameters) cipher1.getPublic()).getY();
	privateKey = ((ElGamalPrivateKeyParameters)cipher1.getPrivate()).getX();
	wellGenerated = true;
	encryptPrivateKey(password);
}
 
开发者ID:pja35,项目名称:p2pEngine,代码行数:15,代码来源:AsymKeysImpl.java


示例4: init

import org.bouncycastle.crypto.params.ElGamalKeyGenerationParameters; //导入依赖的package包/类
public void init(
    KeyGenerationParameters param)
{
    this.param = (ElGamalKeyGenerationParameters)param;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:6,代码来源:ElGamalKeyPairGenerator.java


示例5: generateTest

import org.bouncycastle.crypto.params.ElGamalKeyGenerationParameters; //导入依赖的package包/类
public void generateTest()
    throws Exception
{
    char[]              passPhrase = "hello".toCharArray();
    DSAParametersGenerator  dsaPGen = new DSAParametersGenerator();

    dsaPGen.init(512, 10, new SecureRandom());

    DSAKeyPairGenerator    dsaKpg = new DSAKeyPairGenerator();

    dsaKpg.init(new DSAKeyGenerationParameters(new SecureRandom(), dsaPGen.generateParameters()));

    //
    // this takes a while as the key generator has to generate some DSA params
    // before it generates the key.
    //
    AsymmetricCipherKeyPair  dsaKp = dsaKpg.generateKeyPair();

    ElGamalKeyPairGenerator elgKpg = new ElGamalKeyPairGenerator();
    BigInteger             g = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16);
    BigInteger             p = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16);
    
    ElGamalParameters         elParams = new ElGamalParameters(p, g);
    
    elgKpg.init(new ElGamalKeyGenerationParameters(new SecureRandom(), elParams));

    //
    // this is quicker because we are using pregenerated parameters.
    //
    AsymmetricCipherKeyPair           elgKp = elgKpg.generateKeyPair();
    PGPKeyPair        dsaKeyPair = new BcPGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
    PGPKeyPair        elgKeyPair = new BcPGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());

    PGPKeyRingGenerator    keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
            "test", null, null, null, new BcPGPContentSignerBuilder(PGPPublicKey.DSA, HashAlgorithmTags.SHA1), new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).build(passPhrase));

    keyRingGen.addSubKey(elgKeyPair);

    PGPSecretKeyRing       keyRing = keyRingGen.generateSecretKeyRing();
    
    keyRing.getSecretKey().extractPrivateKey(new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(passPhrase));
    
    PGPPublicKeyRing        pubRing = keyRingGen.generatePublicKeyRing();
    
    PGPPublicKey            vKey = null;
    PGPPublicKey            sKey = null;
    
    Iterator                    it = pubRing.getPublicKeys();
    while (it.hasNext())
    {
        PGPPublicKey    pk = (PGPPublicKey)it.next();
        if (pk.isMasterKey())
        {
            vKey = pk;
        }
        else
        {
            sKey = pk;
        }
    }
    
    Iterator    sIt = sKey.getSignatures();
    while (sIt.hasNext())
    {
        PGPSignature    sig = (PGPSignature)sIt.next();
        
        if (sig.getKeyID() == vKey.getKeyID()
            && sig.getSignatureType() == PGPSignature.SUBKEY_BINDING)
        {
            sig.init(new BcPGPContentVerifierBuilderProvider(), vKey);

            if (!sig.verifyCertification(vKey, sKey))
            {
                fail("failed to verify sub-key signature.");
            }
        }
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:79,代码来源:BcPGPKeyRingTest.java


示例6: generateSha1Test

import org.bouncycastle.crypto.params.ElGamalKeyGenerationParameters; //导入依赖的package包/类
public void generateSha1Test()
    throws Exception
{
    char[]              passPhrase = "hello".toCharArray();
    DSAParametersGenerator  dsaPGen = new DSAParametersGenerator();

    dsaPGen.init(512, 10, new SecureRandom());

    DSAKeyPairGenerator    dsaKpg = new DSAKeyPairGenerator();

    dsaKpg.init(new DSAKeyGenerationParameters(new SecureRandom(), dsaPGen.generateParameters()));

    //
    // this takes a while as the key generator has to generate some DSA params
    // before it generates the key.
    //
    AsymmetricCipherKeyPair dsaKp = dsaKpg.generateKeyPair();

    ElGamalKeyPairGenerator    elgKpg = new ElGamalKeyPairGenerator();
    BigInteger             g = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16);
    BigInteger             p = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16);
    
    ElGamalParameters         elParams = new ElGamalParameters(p, g);
    
    elgKpg.init(new ElGamalKeyGenerationParameters(new SecureRandom(), elParams));

    //
    // this is quicker because we are using pregenerated parameters.
    //
    AsymmetricCipherKeyPair                   elgKp = elgKpg.generateKeyPair();
    PGPKeyPair        dsaKeyPair = new BcPGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
    PGPKeyPair        elgKeyPair = new BcPGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());
    PGPDigestCalculator chkSumCalc = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA1);

    PGPKeyRingGenerator    keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
            "test", chkSumCalc, null, null, new BcPGPContentSignerBuilder(PGPPublicKey.DSA, HashAlgorithmTags.SHA1), new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).build(passPhrase));
    keyRingGen.addSubKey(elgKeyPair);

    PGPSecretKeyRing       keyRing = keyRingGen.generateSecretKeyRing();
    
    keyRing.getSecretKey().extractPrivateKey(new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(passPhrase));
    
    PGPPublicKeyRing        pubRing = keyRingGen.generatePublicKeyRing();
    
    PGPPublicKey            vKey = null;
    PGPPublicKey            sKey = null;
    
    Iterator                    it = pubRing.getPublicKeys();
    while (it.hasNext())
    {
        PGPPublicKey    pk = (PGPPublicKey)it.next();
        if (pk.isMasterKey())
        {
            vKey = pk;
        }
        else
        {
            sKey = pk;
        }
    }
    
    Iterator    sIt = sKey.getSignatures();
    while (sIt.hasNext())
    {
        PGPSignature    sig = (PGPSignature)sIt.next();
        
        if (sig.getKeyID() == vKey.getKeyID()
            && sig.getSignatureType() == PGPSignature.SUBKEY_BINDING)
        {
            sig.init(new BcPGPContentVerifierBuilderProvider(), vKey);

            if (!sig.verifyCertification(vKey, sKey))
            {
                fail("failed to verify sub-key signature.");
            }
        }
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:79,代码来源:BcPGPKeyRingTest.java


示例7: testGeneration

import org.bouncycastle.crypto.params.ElGamalKeyGenerationParameters; //导入依赖的package包/类
/**
 * this test is can take quiet a while
 *
 * @param size size of key in bits.
 */
private void testGeneration(
    int         size)
{
    ElGamalParametersGenerator       pGen = new ElGamalParametersGenerator();

    pGen.init(size, 10, new SecureRandom());

    ElGamalParameters                elParams = pGen.generateParameters();

    if (elParams.getL() != 0)
    {
        fail("ElGamalParametersGenerator failed to set L to 0 in generated ElGamalParameters");
    }

    ElGamalKeyGenerationParameters   params = new ElGamalKeyGenerationParameters(new SecureRandom(), elParams);

    ElGamalKeyPairGenerator          kpGen = new ElGamalKeyPairGenerator();

    kpGen.init(params);

    //
    // generate first pair
    //
    AsymmetricCipherKeyPair         pair = kpGen.generateKeyPair();

    ElGamalPublicKeyParameters      pu = (ElGamalPublicKeyParameters)pair.getPublic();
    ElGamalPrivateKeyParameters     pv = (ElGamalPrivateKeyParameters)pair.getPrivate();

    ElGamalEngine    e = new ElGamalEngine();

    e.init(true, new ParametersWithRandom(pu, new SecureRandom()));

    byte[]  message = Hex.decode("5468697320697320612074657374");

    byte[]  pText = message;
    byte[]  cText = e.processBlock(pText, 0, pText.length);

    e.init(false, pv);

    pText = e.processBlock(cText, 0, cText.length);

    if (!Arrays.areEqual(message, pText))
    {
        fail("generation test failed");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:52,代码来源:ElGamalTest.java


示例8: generate

import org.bouncycastle.crypto.params.ElGamalKeyGenerationParameters; //导入依赖的package包/类
@Override
public AsymmetricCipherKeyPair generate(SecureRandom random) {
    final ElGamalKeyPairGenerator generator = new ElGamalKeyPairGenerator();
    generator.init(new ElGamalKeyGenerationParameters(random, parameters));
    return generator.generateKeyPair();
}
 
开发者ID:codahale,项目名称:gpgj,代码行数:7,代码来源:ElgamalKeyGenerator.java



注:本文中的org.bouncycastle.crypto.params.ElGamalKeyGenerationParameters类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SseBroadcaster类代码示例发布时间:2022-05-22
下一篇:
Java CassandraOperations类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap