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

Java BasicAgreement类代码示例

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

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



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

示例1: IESEngine

import org.bouncycastle.crypto.BasicAgreement; //导入依赖的package包/类
/**
 * set up for use with stream mode, where the key derivation function
 * is used to provide a stream of bytes to xor with the message.
 *
 * @param agree the key agreement used as the basis for the encryption
 * @param kdf   the key derivation function used for byte generation
 * @param mac   the message authentication code generator for the message
 */
public IESEngine(
    BasicAgreement agree,
    DerivationFunction kdf,
    Mac mac)
{
    this.agree = agree;
    this.kdf = kdf;
    this.mac = mac;
    this.macBuf = new byte[mac.getMacSize()];
    this.cipher = null;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:20,代码来源:IESEngine.java


示例2: KeyAgreementSpi

import org.bouncycastle.crypto.BasicAgreement; //导入依赖的package包/类
protected KeyAgreementSpi(
    String kaAlgorithm,
    BasicAgreement agreement,
    DerivationFunction kdf)
{
    this.kaAlgorithm = kaAlgorithm;
    this.agreement = agreement;
    this.kdf = kdf;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:10,代码来源:KeyAgreementSpi.java


示例3: KeyAgreementSpi

import org.bouncycastle.crypto.BasicAgreement; //导入依赖的package包/类
protected KeyAgreementSpi(
    String kaAlgorithm,
    BasicAgreement agreement,
    DerivationFunction kdf)
{
    super(kaAlgorithm, kdf);

    this.kaAlgorithm = kaAlgorithm;
    this.agreement = agreement;
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:11,代码来源:KeyAgreementSpi.java


示例4: IESEngine

import org.bouncycastle.crypto.BasicAgreement; //导入依赖的package包/类
/**
 * set up for use with stream mode, where the key derivation function
 * is used to provide a stream of bytes to xor with the message.
 *
 * @param agree the key agreement used as the basis for the encryption
 * @param kdf the key derivation function used for byte generation
 * @param mac the message authentication code generator for the message
 */
public IESEngine(
    BasicAgreement      agree,
    DerivationFunction  kdf,
    Mac                 mac)
{
    this.agree = agree;
    this.kdf = kdf;
    this.mac = mac;
    this.macBuf = new byte[mac.getMacSize()];
    this.cipher = null;
}
 
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:20,代码来源:IESEngine.java


示例5: JCEECDHKeyAgreement

import org.bouncycastle.crypto.BasicAgreement; //导入依赖的package包/类
protected JCEECDHKeyAgreement(
    BasicAgreement  agreement)
{
    this.agreement = agreement;
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:6,代码来源:JCEECDHKeyAgreement.java


示例6: eciesDecrypt

import org.bouncycastle.crypto.BasicAgreement; //导入依赖的package包/类
public ByteString eciesDecrypt(PrivateKey recipientPrivateKey, ByteString cipherText) {
    BCECPrivateKey bcecPrivateKey = (BCECPrivateKey) recipientPrivateKey;
    ECNamedCurveSpec ecNamedCurveSpec = (ECNamedCurveSpec) bcecPrivateKey.getParams();
    int level = SecurityLevel.from(ecNamedCurveSpec.getName()).size();

    //cipherText = ephemeralPubKeyBytes + encryptedTokBytes + macBytes
    //ephemeralPubKeyBytes = first ((384+7)/8)*2 + 1 bytes = first 97 bytes
    //hmac is sha3_384 = 48 bytes or sha3_256 = 32 bytes
    int ephemeralPubKeyLength = ((level + 7) / 8) * 2 + 1;
    int hmacLength = level >> 3;
    int cipherTextLength = cipherText.size();

    if (cipherTextLength <= ephemeralPubKeyLength + hmacLength)
        throw new RuntimeException(String.format("Illegal cipherText length: %d must be > %d", cipherTextLength, ephemeralPubKeyLength + hmacLength));

    ByteString ephemeralPubKey = cipherText.substring(0, ephemeralPubKeyLength);
    ByteString encryptedContent = cipherText.substring(ephemeralPubKeyLength, cipherTextLength - hmacLength);
    ByteString hmac = cipherText.substring(cipherTextLength - hmacLength);

    ECPrivateKeyParameters ecdhPrivateKeyParameters;
    try {
        ecdhPrivateKeyParameters = (ECPrivateKeyParameters) (PrivateKeyFactory.createKey(bcecPrivateKey.getEncoded()));
    } catch (IOException e) {
        logger.error("ECIES decrypt load private key exception", e);
        throw new RuntimeException(e);
    }
    ECDomainParameters ecDomainParameters = ecdhPrivateKeyParameters.getParameters();
    ECCurve ecCurve = ecDomainParameters.getCurve();
    ECPublicKeyParameters ecPublicKeyParameters = new ECPublicKeyParameters(ecCurve.decodePoint(ephemeralPubKey.toByteArray()), ecDomainParameters);
    BasicAgreement agree = new ECDHBasicAgreement();
    agree.init(ecdhPrivateKeyParameters);
    byte[] keyAgreement = agree.calculateAgreement(ecPublicKeyParameters).toByteArray();

    HKDFParameters hkdfParameters = new HKDFParameters(keyAgreement, null, null);
    HKDFBytesGenerator hkdfBytesGenerator = new HKDFBytesGenerator(digest);
    hkdfBytesGenerator.init(hkdfParameters);
    byte[] hkdfOutputBytes = new byte[AESKEY_LENGTH + HMACKEY_LENGTH];
    hkdfBytesGenerator.generateBytes(hkdfOutputBytes, 0, AESKEY_LENGTH + HMACKEY_LENGTH);
    ByteString hkdfOutput = ByteString.copyFrom(hkdfOutputBytes);
    ByteString aesKey = hkdfOutput.substring(0, AESKEY_LENGTH);
    ByteString hmacKey = hkdfOutput.substring(AESKEY_LENGTH, AESKEY_LENGTH + HMACKEY_LENGTH);
    HMac hMac = new HMac(digest);
    hMac.init(new KeyParameter(hmacKey.toByteArray()));
    hMac.update(encryptedContent.toByteArray(), 0, encryptedContent.size());
    byte[] recoveredHmac = new byte[hMac.getMacSize()];
    hMac.doFinal(recoveredHmac, 0);
    if (!MessageDigest.isEqual(hmac.toByteArray(), recoveredHmac)) {
        throw new RuntimeException("HMAC verify failed");
    }

    CFBBlockCipher aesCipher = new CFBBlockCipher(
            new AESEngine(), BLOCK_BIT_SIZE);
    ByteString iv = encryptedContent.substring(0, IV_LENGTH);
    CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(aesKey.toByteArray()), iv.toByteArray());
    aesCipher.init(false, ivAndKey);
    byte[] decryptedBytes = new byte[500];
    aesCipher.decryptBlock(encryptedContent.substring(IV_LENGTH).toByteArray(), 0, decryptedBytes, 0);
    return ByteString.copyFrom(decryptedBytes);
}
 
开发者ID:GrapeBaBa,项目名称:fabric-java,代码行数:60,代码来源:Crypto.java


示例7: OldIESEngine

import org.bouncycastle.crypto.BasicAgreement; //导入依赖的package包/类
/**
 * set up for use with stream mode, where the key derivation function
 * is used to provide a stream of bytes to xor with the message.
 *
 * @param agree the key agreement used as the basis for the encryption
 * @param kdf   the key derivation function used for byte generation
 * @param mac   the message authentication code generator for the message
 */
public OldIESEngine(
    BasicAgreement agree,
    DerivationFunction kdf,
    Mac mac)
{
    super(agree, kdf, mac);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:16,代码来源:OldIESEngine.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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