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

Java ECDHBasicAgreement类代码示例

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

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



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

示例1: decrypt

import org.spongycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public static byte[] decrypt(ECPoint ephem, BigInteger prv, byte[] IV, byte[] cipher, byte[] macData) throws InvalidCipherTextException {
    AESFastEngine aesFastEngine = new AESFastEngine();

    EthereumIESEngine iesEngine = new EthereumIESEngine(
            new ECDHBasicAgreement(),
            new ConcatKDFBytesGenerator(new SHA256Digest()),
            new HMac(new SHA256Digest()),
            new SHA256Digest(),
            new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));


    byte[]         d = new byte[] {};
    byte[]         e = new byte[] {};

    IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
    ParametersWithIV parametersWithIV =
            new ParametersWithIV(p, IV);

    iesEngine.init(false, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(ephem, CURVE), parametersWithIV);

    return iesEngine.processBlock(cipher, 0, cipher.length, macData);
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:23,代码来源:ECIESCoder.java


示例2: decryptSimple

import org.spongycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
/**
 *  Encryption equivalent to the Crypto++ default ECIES<ECP> settings:
 *
 *  DL_KeyAgreementAlgorithm:        DL_KeyAgreementAlgorithm_DH<struct ECPPoint,struct EnumToType<enum CofactorMultiplicationOption,0> >
 *  DL_KeyDerivationAlgorithm:       DL_KeyDerivationAlgorithm_P1363<struct ECPPoint,0,class P1363_KDF2<class SHA1> >
 *  DL_SymmetricEncryptionAlgorithm: DL_EncryptionAlgorithm_Xor<class HMAC<class SHA1>,0>
 *  DL_PrivateKey:                   DL_Key<ECPPoint>
 *  DL_PrivateKey_EC<class ECP>
 *
 *  Used for Whisper V3
 */
public static byte[] decryptSimple(BigInteger privKey, byte[] cipher) throws IOException, InvalidCipherTextException {
    EthereumIESEngine iesEngine = new EthereumIESEngine(
            new ECDHBasicAgreement(),
            new MGF1BytesGeneratorExt(new SHA1Digest(), 1),
            new HMac(new SHA1Digest()),
            new SHA1Digest(),
            null);

    IESParameters p = new IESParameters(null, null, KEY_SIZE);
    ParametersWithIV parametersWithIV = new ParametersWithIV(p, new byte[0]);

    iesEngine.setHashMacKey(false);

    iesEngine.init(new ECPrivateKeyParameters(privKey, CURVE), parametersWithIV,
            new ECIESPublicKeyParser(ECKey.CURVE));

    return iesEngine.processBlock(cipher, 0, cipher.length);
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:30,代码来源:ECIESCoder.java


示例3: makeIESEngine

import org.spongycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] IV) {
    AESFastEngine aesFastEngine = new AESFastEngine();

    EthereumIESEngine iesEngine = new EthereumIESEngine(
            new ECDHBasicAgreement(),
            new ConcatKDFBytesGenerator(new SHA256Digest()),
            new HMac(new SHA256Digest()),
            new SHA256Digest(),
            new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));


    byte[]         d = new byte[] {};
    byte[]         e = new byte[] {};

    IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
    ParametersWithIV parametersWithIV = new ParametersWithIV(p, IV);

    iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(pub, CURVE), parametersWithIV);
    return iesEngine;
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:21,代码来源:ECIESCoder.java


示例4: makeIESEngine

import org.spongycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] IV) {
    AESFastEngine aesFastEngine = new AESFastEngine();

    EthereumIESEngine iesEngine = new EthereumIESEngine(
            new ECDHBasicAgreement(),
            new ConcatKDFBytesGenerator(new SHA256Digest()),
            new HMac(new SHA256Digest()),
            new SHA256Digest(),
            new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));


    byte[]         d = new byte[] {};
    byte[]         e = new byte[] {};

    IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
    ParametersWithIV parametersWithIV = new ParametersWithIV(p, IV);

    iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, curve), new ECPublicKeyParameters(pub, curve), parametersWithIV);
    return iesEngine;
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:21,代码来源:ECIESTest.java


示例5: decrypt

import org.spongycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public static byte[] decrypt(ECPoint ephem, BigInteger prv, byte[] iv, byte[] cipher, byte[] macData) throws InvalidCipherTextException {
    AESFastEngine aesFastEngine = new AESFastEngine();

    EthereumIESEngine iesEngine = new EthereumIESEngine(
            new ECDHBasicAgreement(),
            new ConcatKDFBytesGenerator(new SHA256Digest()),
            new HMac(new SHA256Digest()),
            new SHA256Digest(),
            new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));


    byte[]         d = new byte[] {};
    byte[]         e = new byte[] {};

    IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
    ParametersWithIV parametersWithIV =
            new ParametersWithIV(p, iv);

    iesEngine.init(false, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(ephem, CURVE), parametersWithIV);

    return iesEngine.processBlock(cipher, 0, cipher.length, macData);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:23,代码来源:ECIESCoder.java


示例6: encryptSimple

import org.spongycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
/**
 *  Encryption equivalent to the Crypto++ default ECIES<ECP> settings:
 *
 *  DL_KeyAgreementAlgorithm:        DL_KeyAgreementAlgorithm_DH<struct ECPPoint,struct EnumToType<enum CofactorMultiplicationOption,0> >
 *  DL_KeyDerivationAlgorithm:       DL_KeyDerivationAlgorithm_P1363<struct ECPPoint,0,class P1363_KDF2<class SHA1> >
 *  DL_SymmetricEncryptionAlgorithm: DL_EncryptionAlgorithm_Xor<class HMAC<class SHA1>,0>
 *  DL_PrivateKey:                   DL_Key<ECPPoint>
 *  DL_PrivateKey_EC<class ECP>
 *
 *  Used for Whisper V3
 */
public static byte[] encryptSimple(ECPoint pub, byte[] plaintext) throws IOException, InvalidCipherTextException {
    EthereumIESEngine iesEngine = new EthereumIESEngine(
            new ECDHBasicAgreement(),
            new MGF1BytesGeneratorExt(new SHA1Digest(), 1),
            new HMac(new SHA1Digest()),
            new SHA1Digest(),
            null);

    IESParameters p = new IESParameters(null, null, KEY_SIZE);
    ParametersWithIV parametersWithIV = new ParametersWithIV(p, new byte[0]);

    iesEngine.setHashMacKey(false);

    ECKeyPairGenerator eGen = new ECKeyPairGenerator();
    SecureRandom random = new SecureRandom();
    KeyGenerationParameters gParam = new ECKeyGenerationParameters(CURVE, random);
    eGen.init(gParam);

    EphemeralKeyPairGenerator ephemeralKeyPairGenerator =
            new EphemeralKeyPairGenerator(/*testGen*/eGen, new ECIESPublicKeyEncoder());

    iesEngine.init(new ECPublicKeyParameters(pub, CURVE), parametersWithIV, ephemeralKeyPairGenerator);

    return iesEngine.processBlock(plaintext, 0, plaintext.length);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:37,代码来源:ECIESCoder.java


示例7: makeIESEngine

import org.spongycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] iv) {
    AESFastEngine aesFastEngine = new AESFastEngine();

    EthereumIESEngine iesEngine = new EthereumIESEngine(
            new ECDHBasicAgreement(),
            new ConcatKDFBytesGenerator(new SHA256Digest()),
            new HMac(new SHA256Digest()),
            new SHA256Digest(),
            new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));


    byte[]         d = new byte[] {};
    byte[]         e = new byte[] {};

    IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
    ParametersWithIV parametersWithIV = new ParametersWithIV(p, iv);

    iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(pub, CURVE), parametersWithIV);
    return iesEngine;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:21,代码来源:ECIESCoder.java


示例8: encryptSimple

import org.spongycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
/**
     *  Encryption equivalent to the Crypto++ default ECIES<ECP> settings:
     *
     *  DL_KeyAgreementAlgorithm:        DL_KeyAgreementAlgorithm_DH<struct ECPPoint,struct EnumToType<enum CofactorMultiplicationOption,0> >
     *  DL_KeyDerivationAlgorithm:       DL_KeyDerivationAlgorithm_P1363<struct ECPPoint,0,class P1363_KDF2<class SHA1> >
     *  DL_SymmetricEncryptionAlgorithm: DL_EncryptionAlgorithm_Xor<class HMAC<class SHA1>,0>
     *  DL_PrivateKey:                   DL_Key<ECPPoint>
     *  DL_PrivateKey_EC<class ECP>
     *
     *  Used for Whisper V3
     */
    public static byte[] encryptSimple(ECPoint pub, byte[] plaintext) throws IOException, InvalidCipherTextException {
        EthereumIESEngine iesEngine = new EthereumIESEngine(
                new ECDHBasicAgreement(),
                new MGF1BytesGeneratorExt(new SHA1Digest(), 1),
                new HMac(new SHA1Digest()),
                new SHA1Digest(),
                null);

        IESParameters p = new IESParameters(null, null, KEY_SIZE);
        ParametersWithIV parametersWithIV = new ParametersWithIV(p, new byte[0]);

        iesEngine.setHashMacKey(false);

        ECKeyPairGenerator eGen = new ECKeyPairGenerator();
        SecureRandom random = new SecureRandom();
        KeyGenerationParameters gParam = new ECKeyGenerationParameters(CURVE, random);
        eGen.init(gParam);

//        AsymmetricCipherKeyPairGenerator testGen = new AsymmetricCipherKeyPairGenerator() {
//            ECKey priv = ECKey.fromPrivate(Hex.decode("d0b043b4c5d657670778242d82d68a29d25d7d711127d17b8e299f156dad361a"));
//
//            @Override
//            public void init(KeyGenerationParameters keyGenerationParameters) {
//            }
//
//            @Override
//            public AsymmetricCipherKeyPair generateKeyPair() {
//                return new AsymmetricCipherKeyPair(new ECPublicKeyParameters(priv.getPubKeyPoint(), CURVE),
//                        new ECPrivateKeyParameters(priv.getPrivKey(), CURVE));
//            }
//        };

        EphemeralKeyPairGenerator ephemeralKeyPairGenerator =
                new EphemeralKeyPairGenerator(/*testGen*/eGen, new ECIESPublicKeyEncoder());

        iesEngine.init(new ECPublicKeyParameters(pub, CURVE), parametersWithIV, ephemeralKeyPairGenerator);

        return iesEngine.processBlock(plaintext, 0, plaintext.length);
    }
 
开发者ID:talentchain,项目名称:talchain,代码行数:51,代码来源:ECIESCoder.java


示例9: ECIES

import org.spongycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public ECIES() {
    super(new IESEngine(new ECDHBasicAgreement(),
            new KDF2BytesGenerator(new SHA1Digest()),
            new HMac(new SHA1Digest())));
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:6,代码来源:IESCipher.java


示例10: ECIESwithCipher

import org.spongycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public ECIESwithCipher(BlockCipher cipher) {
    super(new IESEngine(new ECDHBasicAgreement(),
            new KDF2BytesGenerator(new SHA1Digest()),
            new HMac(new SHA1Digest()),
            new PaddedBufferedBlockCipher(cipher)));
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:7,代码来源:IESCipher.java


示例11: OldECIES

import org.spongycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public OldECIES() {
    super(new OldIESEngine(new ECDHBasicAgreement(),
            new KDF2BytesGenerator(new SHA1Digest()),
            new HMac(new SHA1Digest())));
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:6,代码来源:IESCipher.java


示例12: OldECIESwithCipher

import org.spongycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public OldECIESwithCipher(BlockCipher baseCipher) {
    super(new OldIESEngine(new ECDHBasicAgreement(),
            new KDF2BytesGenerator(new SHA1Digest()),
            new HMac(new SHA1Digest()),
            new PaddedBufferedBlockCipher(baseCipher)));
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:7,代码来源:IESCipher.java


示例13: IV

import org.spongycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
@Test  // ECIES_AES128_SHA256 + No Ephemeral Key + IV(all zeroes)
public void test14() throws Throwable{

    AESFastEngine aesFastEngine = new AESFastEngine();

    IESEngine iesEngine = new IESEngine(
            new ECDHBasicAgreement(),
            new KDF2BytesGenerator(new SHA256Digest()),
            new HMac(new SHA256Digest()),
            new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));


    byte[]         d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
    byte[]         e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };

    IESParameters p = new IESWithCipherParameters(d, e, 64, 128);
    ParametersWithIV parametersWithIV = new ParametersWithIV(p, new byte[16]);

    ECKeyPairGenerator eGen = new ECKeyPairGenerator();
    KeyGenerationParameters gParam = new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom());

    eGen.init(gParam);


    AsymmetricCipherKeyPair p1 = eGen.generateKeyPair();
    AsymmetricCipherKeyPair p2 = eGen.generateKeyPair();


    ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom());
    ECKeyPairGenerator generator = new ECKeyPairGenerator();
    generator.init(keygenParams);

    ECKeyPairGenerator gen = new ECKeyPairGenerator();
    gen.init(new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom()));

    iesEngine.init(true, p1.getPrivate(), p2.getPublic(), parametersWithIV);

    byte[] message = Hex.decode("010101");
    log.info("payload: {}", Hex.toHexString(message));


    byte[] cipher = iesEngine.processBlock(message, 0, message.length);
    log.info("cipher: {}", Hex.toHexString(cipher));


    IESEngine decryptorIES_Engine = new IESEngine(
            new ECDHBasicAgreement(),
            new KDF2BytesGenerator (new SHA256Digest()),
            new HMac(new SHA256Digest()),
            new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));

    decryptorIES_Engine.init(false, p2.getPrivate(), p1.getPublic(), parametersWithIV);

    byte[] orig = decryptorIES_Engine.processBlock(cipher, 0, cipher.length);

    log.info("orig: " + Hex.toHexString(orig));
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:58,代码来源:CryptoTest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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