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


Java MacOutputStream类代码示例

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


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

示例1: createMacCalculator

import org.bouncycastle.crypto.io.MacOutputStream; //导入依赖的package包/类
static MacCalculator createMacCalculator(final ASN1ObjectIdentifier digestAlgorithm, ExtendedDigest digest, final PKCS12PBEParams pbeParams, final char[] password)
{
    PKCS12ParametersGenerator pGen = new PKCS12ParametersGenerator(digest);

    pGen.init(PKCS12ParametersGenerator.PKCS12PasswordToBytes(password), pbeParams.getIV(), pbeParams.getIterations().intValue());

    final KeyParameter keyParam = (KeyParameter)pGen.generateDerivedMacParameters(digest.getDigestSize() * 8);

    final HMac hMac = new HMac(digest);

    hMac.init(keyParam);

    return new MacCalculator()
    {
        public AlgorithmIdentifier getAlgorithmIdentifier()
        {
            return new AlgorithmIdentifier(digestAlgorithm, pbeParams);
        }

        public OutputStream getOutputStream()
        {
            return new MacOutputStream(hMac);
        }

        public byte[] getMac()
        {
            byte[] res = new byte[hMac.getMacSize()];

            hMac.doFinal(res, 0);

            return res;
        }

        public GenericKey getKey()
        {
            return new GenericKey(getAlgorithmIdentifier(), PKCS12ParametersGenerator.PKCS12PasswordToBytes(password));
        }
    };
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:40,代码来源:PKCS12PBEUtils.java

示例2: engineStore

import org.bouncycastle.crypto.io.MacOutputStream; //导入依赖的package包/类
public void engineStore(OutputStream stream, char[] password) 
    throws IOException
{
    DataOutputStream    dOut = new DataOutputStream(stream);
    byte[]              salt = new byte[STORE_SALT_SIZE];
    int                 iterationCount = MIN_ITERATIONS + (random.nextInt() & 0x3ff);

    random.nextBytes(salt);

    dOut.writeInt(version);
    dOut.writeInt(salt.length);
    dOut.write(salt);
    dOut.writeInt(iterationCount);

    HMac                    hMac = new HMac(new SHA1Digest());
    MacOutputStream         mOut = new MacOutputStream(hMac);
    PBEParametersGenerator  pbeGen = new PKCS12ParametersGenerator(new SHA1Digest());
    byte[]                  passKey = PBEParametersGenerator.PKCS12PasswordToBytes(password);

    pbeGen.init(passKey, salt, iterationCount);

    if (version < 2)
    {
        hMac.init(pbeGen.generateDerivedMacParameters(hMac.getMacSize()));
    }
    else
    {
        hMac.init(pbeGen.generateDerivedMacParameters(hMac.getMacSize() * 8));
    }

    for (int i = 0; i != passKey.length; i++)
    {
        passKey[i] = 0;
    }

    saveStore(new TeeOutputStream(dOut, mOut));

    byte[]  mac = new byte[hMac.getMacSize()];

    hMac.doFinal(mac, 0);

    dOut.write(mac);

    dOut.close();
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:46,代码来源:BcKeyStoreSpi.java


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