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

Java PBMParameter类代码示例

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

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



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

示例1: isValid

import org.bouncycastle.asn1.cmp.PBMParameter; //导入依赖的package包/类
public boolean isValid(PKMACValue value, char[] password, SubjectPublicKeyInfo keyInfo)
    throws CRMFException
{
    builder.setParameters(PBMParameter.getInstance(value.getAlgId().getParameters()));
    MacCalculator calculator = builder.build(password);

    OutputStream macOut = calculator.getOutputStream();

    try
    {
        macOut.write(keyInfo.getEncoded(ASN1Encoding.DER));

        macOut.close();
    }
    catch (IOException e)
    {
        throw new CRMFException("exception encoding mac input: " + e.getMessage(), e);
    }

    return Arrays.areEqual(calculator.getMac(), value.getValue().getBytes());
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:22,代码来源:PKMACValueVerifier.java


示例2: build

import org.bouncycastle.asn1.cmp.PBMParameter; //导入依赖的package包/类
public MacCalculator build(char[] password)
    throws CRMFException
{
    if (parameters != null)
    {
        return genCalculator(parameters, password);
    }
    else
    {
        byte[] salt = new byte[saltLength];

        if (random == null)
        {
            this.random = new SecureRandom();
        }

        random.nextBytes(salt);

        return genCalculator(new PBMParameter(salt, owf, iterationCount, mac), password);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:22,代码来源:PKMACBuilder.java


示例3: setParameters

import org.bouncycastle.asn1.cmp.PBMParameter; //导入依赖的package包/类
public PKMACBuilder setParameters(PBMParameter parameters)
{
    checkIterationCountCeiling(parameters.getIterationCount().getValue().intValue());

    this.parameters = parameters;

    return this;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:9,代码来源:PKMACBuilder.java


示例4: verify

import org.bouncycastle.asn1.cmp.PBMParameter; //导入依赖的package包/类
/**
 * Verify a message with password based MAC protection.
 *
 * @param pkMacBuilder MAC builder that can be used to construct the appropriate MacCalculator
 * @param password the MAC password
 * @return true if the passed in password and MAC builder verify the message, false otherwise.
 * @throws CMPException if algorithm not MAC based, or an exception is thrown verifying the MAC.
 */
public boolean verify(PKMACBuilder pkMacBuilder, char[] password)
    throws CMPException
{
    if (!CMPObjectIdentifiers.passwordBasedMac.equals(pkiMessage.getHeader().getProtectionAlg().getAlgorithm()))
    {
        throw new CMPException("protection algorithm not mac based");
    }

    try
    {
        pkMacBuilder.setParameters(PBMParameter.getInstance(pkiMessage.getHeader().getProtectionAlg().getParameters()));
        MacCalculator calculator = pkMacBuilder.build(password);

        OutputStream macOut = calculator.getOutputStream();

        ASN1EncodableVector v = new ASN1EncodableVector();

        v.add(pkiMessage.getHeader());
        v.add(pkiMessage.getBody());

        macOut.write(new DERSequence(v).getEncoded(ASN1Encoding.DER));

        macOut.close();

        return Arrays.areEqual(calculator.getMac(), pkiMessage.getProtection().getBytes());
    }
    catch (Exception e)
    {
        throw new CMPException("unable to verify MAC: " + e.getMessage(), e);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:40,代码来源:ProtectedPKIMessage.java


示例5: PKMACValue

import org.bouncycastle.asn1.cmp.PBMParameter; //导入依赖的package包/类
/**
 * Creates a new PKMACValue.
 * @param params parameters for password-based MAC
 * @param value MAC of the DER-encoded SubjectPublicKeyInfo
 */
public PKMACValue(
    PBMParameter params,
    DERBitString value)
{
    this(new AlgorithmIdentifier(
                CMPObjectIdentifiers.passwordBasedMac, params), value);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:13,代码来源:PKMACValue.java


示例6: genCalculator

import org.bouncycastle.asn1.cmp.PBMParameter; //导入依赖的package包/类
private MacCalculator genCalculator(final PBMParameter params, char[] password)
    throws CRMFException
{
    // From RFC 4211
    //
    //   1.  Generate a random salt value S
    //
    //   2.  Append the salt to the pw.  K = pw || salt.
    //
    //   3.  Hash the value of K.  K = HASH(K)
    //
    //   4.  Iter = Iter - 1.  If Iter is greater than zero.  Goto step 3.
    //
    //   5.  Compute an HMAC as documented in [HMAC].
    //
    //       MAC = HASH( K XOR opad, HASH( K XOR ipad, data) )
    //
    //       Where opad and ipad are defined in [HMAC].
    byte[] pw = Strings.toUTF8ByteArray(password);
    byte[] salt = params.getSalt().getOctets();
    byte[] K = new byte[pw.length + salt.length];

    System.arraycopy(pw, 0, K, 0, pw.length);
    System.arraycopy(salt, 0, K, pw.length, salt.length);

    calculator.setup(params.getOwf(), params.getMac());

    int iter = params.getIterationCount().getValue().intValue();
    do
    {
        K = calculator.calculateDigest(K);
    }
    while (--iter > 0);

    final byte[] key = K;

    return new MacCalculator()
    {
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();

        public AlgorithmIdentifier getAlgorithmIdentifier()
        {
            return new AlgorithmIdentifier(CMPObjectIdentifiers.passwordBasedMac, params);
        }

        public GenericKey getKey()
        {
            return new GenericKey(getAlgorithmIdentifier(), key);
        }

        public OutputStream getOutputStream()
        {
            return bOut;
        }

        public byte[] getMac()
        {
            try
            {
                return calculator.calculateMac(key, bOut.toByteArray());
            }
            catch (CRMFException e)
            {
                throw new RuntimeOperatorException("exception calculating mac: " + e.getMessage(), e);
            }
        }
    };
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:69,代码来源:PKMACBuilder.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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