当前位置: 首页>>代码示例>>Java>>正文


Java ECDHBasicAgreement.init方法代码示例

本文整理汇总了Java中org.bouncycastle.crypto.agreement.ECDHBasicAgreement.init方法的典型用法代码示例。如果您正苦于以下问题:Java ECDHBasicAgreement.init方法的具体用法?Java ECDHBasicAgreement.init怎么用?Java ECDHBasicAgreement.init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.crypto.agreement.ECDHBasicAgreement的用法示例。


在下文中一共展示了ECDHBasicAgreement.init方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateSharedSecret

import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入方法依赖的package包/类
/**
 * Generate a shared AES key using ECDH.
 */
public static byte[] generateSharedSecret(byte[] privateKey, byte[] publicKey) {
  try {
    ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(SECP256K1);
    ECDomainParameters domain =
        new ECDomainParameters(spec.getCurve(), spec.getG(), spec.getN(), spec.getH());
    ECPublicKeyParameters pubKey =
        new ECPublicKeyParameters(spec.getCurve().decodePoint(publicKey), domain);
    ECPrivateKeyParameters prvkey =
        new ECPrivateKeyParameters(new BigInteger(1, privateKey), domain);

    ECDHBasicAgreement agreement = new ECDHBasicAgreement();
    agreement.init(prvkey);
    byte[] password = agreement.calculateAgreement(pubKey).toByteArray();

    return Aes.generateKey(ByteUtilities.toHexString(password), password);

  } catch (Exception e) {
    LOGGER.error(null, e);
    return new byte[0];
  }
}
 
开发者ID:Braveno,项目名称:cosigner,代码行数:25,代码来源:Secp256k1.java

示例2: curveTest

import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入方法依赖的package包/类
@Test
public void curveTest() {
    final X9ECParameters curve = NISTNamedCurves.getByName("P-384");
    final ECDomainParameters domainParameters = new ECDomainParameters(
            curve.getCurve(), curve.getG(), curve.getN());
    final SecureRandom random = new SecureRandom();
    final ECKeyPairGenerator gen = new ECKeyPairGenerator();
    gen.init(new ECKeyGenerationParameters(domainParameters, random));
    final AsymmetricCipherKeyPair senderPair = gen.generateKeyPair();
    final AsymmetricCipherKeyPair receiverPair = gen.generateKeyPair();
    final ECDHBasicAgreement senderAgreement = new ECDHBasicAgreement();
    senderAgreement.init(senderPair.getPrivate());
    final BigInteger senderResult = senderAgreement.calculateAgreement(
            receiverPair.getPublic());
    final ECDHBasicAgreement receiverAgreement = new ECDHBasicAgreement();
    receiverAgreement.init(receiverPair.getPrivate());
    final BigInteger receiverResult = receiverAgreement.calculateAgreement(
            senderPair.getPublic());
    assertEquals(senderResult, receiverResult);
    //System.out.println(receiverResult);
}
 
开发者ID:lshift,项目名称:bletchley,代码行数:22,代码来源:EcdhTest.java

示例3: calculateECDHBasicAgreement

import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入方法依赖的package包/类
public static byte[] calculateECDHBasicAgreement(ECPublicKeyParameters publicKey, ECPrivateKeyParameters privateKey)
{

    ECDHBasicAgreement basicAgreement = new ECDHBasicAgreement();
    basicAgreement.init(privateKey);
    BigInteger agreementValue = basicAgreement.calculateAgreement(publicKey);

    /*
     * RFC 4492 5.10. Note that this octet string (Z in IEEE 1363 terminology) as output by
     * FE2OSP, the Field Element to Octet String Conversion Primitive, has constant length for
     * any given field; leading zeros found in this octet string MUST NOT be truncated.
     */
    return BigIntegers.asUnsignedByteArray(basicAgreement.getFieldSize(), agreementValue);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:15,代码来源:TlsECCUtils.java

示例4: calculateECDHBasicAgreement

import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入方法依赖的package包/类
public static byte[] calculateECDHBasicAgreement(ECPublicKeyParameters publicKey, ECPrivateKeyParameters privateKey)
{
    ECDHBasicAgreement basicAgreement = new ECDHBasicAgreement();
    basicAgreement.init(privateKey);
    BigInteger agreementValue = basicAgreement.calculateAgreement(publicKey);

    /*
     * RFC 4492 5.10. Note that this octet string (Z in IEEE 1363 terminology) as output by
     * FE2OSP, the Field Element to Octet String Conversion Primitive, has constant length for
     * any given field; leading zeros found in this octet string MUST NOT be truncated.
     */
    return BigIntegers.asUnsignedByteArray(basicAgreement.getFieldSize(), agreementValue);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:14,代码来源:TlsECCUtils.java

示例5: main

import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入方法依赖的package包/类
public static void main( String[] args ) throws InvalidKeySpecException, InvalidKeyException, IOException {
    ECPublicKey clientKey = (ECPublicKey) ECDH_KEY_FACTORY.generatePublic( new X509EncodedKeySpec( Base64.getDecoder().decode( "MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEDEKneqEvcqUqqFMM1HM1A4zWjJC+I8Y+aKzG5dl+6wNOHHQ4NmG2PEXRJYhujyodFH+wO0dEr4GM1WoaWog8xsYQ6mQJAC0eVpBM96spUB1eMN56+BwlJ4H3Qx4TAvAs" ) ) );
    ECPrivateKey privateKey = (ECPrivateKey) ECDH_KEY_FACTORY.generatePrivate( new PKCS8EncodedKeySpec( Base64.getDecoder().decode( "MB8CAQAwEAYHKoZIzj0CAQYFK4EEACIECDAGAgEBBAEB" ) ) );

    ECDHBasicAgreement agreement = new ECDHBasicAgreement();
    agreement.init( PrivateKeyFactory.createKey( privateKey.getEncoded() ) );
    byte[] secret = agreement.calculateAgreement( PublicKeyFactory.createKey( clientKey.getEncoded() ) ).toByteArray();

    System.out.println( Util.toHexString( secret ) );
    System.out.println( Util.toHexString( Base64.getDecoder().decode( "DEKneqEvcqUqqFMM1HM1A4zWjJC+I8Y+aKzG5dl+6wNOHHQ4NmG2PEXRJYhujyod" ) ) );
}
 
开发者ID:GoMint,项目名称:Proxy,代码行数:12,代码来源:CryptoTest.java

示例6: sessionKey

import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入方法依赖的package包/类
public static AesKey sessionKey(
        final CipherParameters receiverKey,
        final CipherParameters senderKey,
        final CipherParameters privateKey,
        final ECPublicKeyParameters publicKey
) {
    final ECDHBasicAgreement senderAgreement = new ECDHBasicAgreement();
    senderAgreement.init(privateKey);
    final EcdhSharedSecret sharedSecret = new EcdhSharedSecret(
        ((ECPublicKeyParameters)receiverKey).getQ(),
        ((ECPublicKeyParameters)senderKey).getQ(),
        senderAgreement.calculateAgreement(publicKey));
    final DigestSha384 hash = DigestSha384.digest(sharedSecret);
    return new AesKey(Arrays.copyOf(hash.getBytes(), AesKey.AES_KEY_BYTES));
}
 
开发者ID:lshift,项目名称:bletchley,代码行数:16,代码来源:Ec.java


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