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


Java PKCS12ParametersGenerator.generateDerivedParameters方法代码示例

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


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

示例1: createCipherParameters

import org.bouncycastle.crypto.generators.PKCS12ParametersGenerator; //导入方法依赖的package包/类
static CipherParameters createCipherParameters(ASN1ObjectIdentifier algorithm, ExtendedDigest digest, int blockSize, PKCS12PBEParams pbeParams, char[] password)
{
    PKCS12ParametersGenerator pGen = new PKCS12ParametersGenerator(digest);

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

    CipherParameters params;

    if (PKCS12PBEUtils.hasNoIv(algorithm))
    {
        params = pGen.generateDerivedParameters(PKCS12PBEUtils.getKeySize(algorithm));
    }
    else
    {
        params = pGen.generateDerivedParameters(PKCS12PBEUtils.getKeySize(algorithm), blockSize * 8);

        if (PKCS12PBEUtils.isDesAlg(algorithm))
        {
            DESedeParameters.setOddParity(((KeyParameter)((ParametersWithIV)params).getParameters()).getKey());
        }
    }
    return params;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:24,代码来源:PKCS12PBEUtils.java

示例2: decrypt

import org.bouncycastle.crypto.generators.PKCS12ParametersGenerator; //导入方法依赖的package包/类
/**
 * A password-based data decryption using a constant salt value "<b>constantSalt</b>"
 * @param cipher
 * @param password
 * @param salt
 * @param iterationCount
 * @return
 * @throws Exception
 */
public static byte[] decrypt(byte[] cipher, String password) throws Exception
{
    PKCS12ParametersGenerator pGen = new PKCS12ParametersGenerator(new SHA256Digest());
    char[] passwordChars = password.toCharArray();
    final byte[] pkcs12PasswordBytes = PBEParametersGenerator.PKCS12PasswordToBytes(passwordChars);
    pGen.init(pkcs12PasswordBytes, constantSalt.getBytes(), iterations);
    CBCBlockCipher aesCBC = new CBCBlockCipher(new AESEngine());
    ParametersWithIV aesCBCParams = (ParametersWithIV) pGen.generateDerivedParameters(256, 128);
    aesCBC.init(false, aesCBCParams);
    PaddedBufferedBlockCipher aesCipher = new PaddedBufferedBlockCipher(aesCBC, new PKCS7Padding());
    byte[] plainTemp = new byte[aesCipher.getOutputSize(cipher.length)];
    int offset = aesCipher.processBytes(cipher, 0, cipher.length, plainTemp, 0);
    int last = aesCipher.doFinal(plainTemp, offset);
    final byte[] plain = new byte[offset + last];
    System.arraycopy(plainTemp, 0, plain, 0, plain.length);
    return plain;
}
 
开发者ID:giuseppeurso-eu,项目名称:java-security,代码行数:27,代码来源:PasswordBasedEncryption.java


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