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

Java DHKeyPairGenerator类代码示例

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

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



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

示例1: generateServerKeyExchange

import org.bouncycastle.crypto.generators.DHKeyPairGenerator; //导入依赖的package包/类
public byte[] generateServerKeyExchange()
    throws IOException
{

    if (this.dhParameters == null)
    {
        throw new TlsFatalAlert(AlertDescription.internal_error);
    }

    ByteArrayOutputStream buf = new ByteArrayOutputStream();

    DHKeyPairGenerator kpg = new DHKeyPairGenerator();
    kpg.init(new DHKeyGenerationParameters(context.getSecureRandom(), this.dhParameters));
    AsymmetricCipherKeyPair kp = kpg.generateKeyPair();

    BigInteger Ys = ((DHPublicKeyParameters)kp.getPublic()).getY();

    TlsDHUtils.writeDHParameter(dhParameters.getP(), buf);
    TlsDHUtils.writeDHParameter(dhParameters.getG(), buf);
    TlsDHUtils.writeDHParameter(Ys, buf);

    byte[] digestInput = buf.toByteArray();

    Digest d = new CombinedHash();
    SecurityParameters securityParameters = context.getSecurityParameters();
    d.update(securityParameters.clientRandom, 0, securityParameters.clientRandom.length);
    d.update(securityParameters.serverRandom, 0, securityParameters.serverRandom.length);
    d.update(digestInput, 0, digestInput.length);

    byte[] hash = new byte[d.getDigestSize()];
    d.doFinal(hash, 0);

    byte[] sigBytes = serverCredentials.generateCertificateSignature(hash);
    /*
     * TODO RFC 5246 4.7. digitally-signed element needs SignatureAndHashAlgorithm prepended from TLS 1.2
     */
    TlsUtils.writeOpaque16(sigBytes, buf);

    return buf.toByteArray();
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:41,代码来源:TlsDHEKeyExchange.java


示例2: calculateMessage

import org.bouncycastle.crypto.generators.DHKeyPairGenerator; //导入依赖的package包/类
/**
 * calculate our initial message.
 */
public BigInteger calculateMessage()
{
    DHKeyPairGenerator dhGen = new DHKeyPairGenerator();
    dhGen.init(new DHKeyGenerationParameters(random, dhParams));
    AsymmetricCipherKeyPair dhPair = dhGen.generateKeyPair();

    this.privateValue = ((DHPrivateKeyParameters)dhPair.getPrivate()).getX();

    return ((DHPublicKeyParameters)dhPair.getPublic()).getY();
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:14,代码来源:DHAgreement.java


示例3: testGPWithRandom

import org.bouncycastle.crypto.generators.DHKeyPairGenerator; //导入依赖的package包/类
private void testGPWithRandom(
    DHKeyPairGenerator kpGen)
{
    //
    // generate first pair
    //
    AsymmetricCipherKeyPair     pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu1 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv1 = (DHPrivateKeyParameters)pair.getPrivate();
    //
    // generate second pair
    //
    pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu2 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv2 = (DHPrivateKeyParameters)pair.getPrivate();

    //
    // two way
    //
    DHAgreement    e1 = new DHAgreement();
    DHAgreement    e2 = new DHAgreement();

    e1.init(new ParametersWithRandom(pv1, new SecureRandom()));
    e2.init(new ParametersWithRandom(pv2, new SecureRandom()));

    BigInteger   m1 = e1.calculateMessage();
    BigInteger   m2 = e2.calculateMessage();

    BigInteger   k1 = e1.calculateAgreement(pu2, m2);
    BigInteger   k2 = e2.calculateAgreement(pu1, m1);
    
    if (!k1.equals(k2))
    {
        fail("basic with random 2-way test failed");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:39,代码来源:DHTest.java


示例4: getDHKeyPairGenerator

import org.bouncycastle.crypto.generators.DHKeyPairGenerator; //导入依赖的package包/类
private DHKeyPairGenerator getDHKeyPairGenerator(
    BigInteger g,
    BigInteger p)
{
    DHParameters                dhParams = new DHParameters(p, g);
    DHKeyGenerationParameters   params = new DHKeyGenerationParameters(new SecureRandom(), dhParams);
    DHKeyPairGenerator          kpGen = new DHKeyPairGenerator();

    kpGen.init(params);
    
    return kpGen;
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:13,代码来源:DHTest.java


示例5: testDH

import org.bouncycastle.crypto.generators.DHKeyPairGenerator; //导入依赖的package包/类
private void testDH(
    int         size,
    BigInteger  g,
    BigInteger  p)
{
    DHKeyPairGenerator kpGen = getDHKeyPairGenerator(g, p);

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

    DHPublicKeyParameters       pu1 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv1 = (DHPrivateKeyParameters)pair.getPrivate();
    //
    // generate second pair
    //
    pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu2 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv2 = (DHPrivateKeyParameters)pair.getPrivate();

    //
    // two way
    //
    DHAgreement    e1 = new DHAgreement();
    DHAgreement    e2 = new DHAgreement();

    e1.init(pv1);
    e2.init(pv2);

    BigInteger  m1 = e1.calculateMessage();
    BigInteger  m2 = e2.calculateMessage();

    BigInteger   k1 = e1.calculateAgreement(pu2, m2);
    BigInteger   k2 = e2.calculateAgreement(pu1, m1);

    if (!k1.equals(k2))
    {
        fail(size + " bit 2-way test failed");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:43,代码来源:DHTest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java DeviceEvent类代码示例发布时间:2022-05-22
下一篇:
Java GeoServerRESTPublisher类代码示例发布时间: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