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

Java PBES2Parameters类代码示例

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

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



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

示例1: createCipher

import org.bouncycastle.asn1.pkcs.PBES2Parameters; //导入依赖的package包/类
private Cipher createCipher(int mode, char[] password, AlgorithmIdentifier algId)
    throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, NoSuchProviderException
{
    PBES2Parameters alg = PBES2Parameters.getInstance(algId.getParameters());
    PBKDF2Params func = PBKDF2Params.getInstance(alg.getKeyDerivationFunc().getParameters());
    AlgorithmIdentifier encScheme = AlgorithmIdentifier.getInstance(alg.getEncryptionScheme());

    SecretKeyFactory keyFact = helper.createSecretKeyFactory(alg.getKeyDerivationFunc().getAlgorithm().getId());
    SecretKey key;

    if (func.isDefaultPrf())
    {
        key = keyFact.generateSecret(new PBEKeySpec(password, func.getSalt(), func.getIterationCount().intValue(), keySizeProvider.getKeySize(encScheme)));
    }
    else
    {
        key = keyFact.generateSecret(new PBKDF2KeySpec(password, func.getSalt(), func.getIterationCount().intValue(), keySizeProvider.getKeySize(encScheme), func.getPrf()));
    }

    Cipher cipher = Cipher.getInstance(alg.getEncryptionScheme().getAlgorithm().getId());

    AlgorithmIdentifier encryptionAlg = AlgorithmIdentifier.getInstance(alg.getEncryptionScheme());

    ASN1Encodable encParams = alg.getEncryptionScheme().getParameters();
    if (encParams instanceof ASN1OctetString)
    {
        cipher.init(mode, key, new IvParameterSpec(ASN1OctetString.getInstance(encParams).getOctets()));
    }
    else
    {
        // TODO: at the moment it's just GOST, but...
        GOST28147Parameters gParams = GOST28147Parameters.getInstance(encParams);

        cipher.init(mode, key, new GOST28147ParameterSpec(gParams.getEncryptionParamSet(), gParams.getIV()));
    }
    return cipher;
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:38,代码来源:PKCS12KeyStoreSpi.java


示例2: createCipher

import org.bouncycastle.asn1.pkcs.PBES2Parameters; //导入依赖的package包/类
private Cipher createCipher(int mode, char[] password, AlgorithmIdentifier algId)
    throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException
{
    PBES2Parameters alg = PBES2Parameters.getInstance(algId.getParameters());
    PBKDF2Params func = PBKDF2Params.getInstance(alg.getKeyDerivationFunc().getParameters());
    AlgorithmIdentifier encScheme = AlgorithmIdentifier.getInstance(alg.getEncryptionScheme());

    SecretKeyFactory keyFact = SecretKeyFactory.getInstance(alg.getKeyDerivationFunc().getAlgorithm().getId(), bcProvider);
    SecretKey key;

    if (func.isDefaultPrf())
    {
        key = keyFact.generateSecret(new PBEKeySpec(password, func.getSalt(), func.getIterationCount().intValue(), keySizeProvider.getKeySize(encScheme)));
    }
    else
    {
        key = keyFact.generateSecret(new PBKDF2KeySpec(password, func.getSalt(), func.getIterationCount().intValue(), keySizeProvider.getKeySize(encScheme), func.getPrf()));
    }

    Cipher cipher = Cipher.getInstance(alg.getEncryptionScheme().getAlgorithm().getId());

    AlgorithmIdentifier encryptionAlg = AlgorithmIdentifier.getInstance(alg.getEncryptionScheme());

    ASN1Encodable encParams = alg.getEncryptionScheme().getParameters();
    if (encParams instanceof ASN1OctetString)
    {
        cipher.init(mode, key, new IvParameterSpec(ASN1OctetString.getInstance(encParams).getOctets()));
    }
    else
    {
        // TODO: at the moment it's just GOST, but...
        GOST28147Parameters gParams = GOST28147Parameters.getInstance(encParams);

        cipher.init(mode, key, new GOST28147ParameterSpec(gParams.getEncryptionParamSet(), gParams.getIV()));
    }
    return cipher;
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:38,代码来源:PKCS12KeyStoreSpi.java


示例3: build

import org.bouncycastle.asn1.pkcs.PBES2Parameters; //导入依赖的package包/类
public InputDecryptorProvider build(final char[] password)
{
    return new InputDecryptorProvider()
    {
        private Cipher cipher;
        private AlgorithmIdentifier encryptionAlg;

        public InputDecryptor get(final AlgorithmIdentifier algorithmIdentifier)
            throws OperatorCreationException
        {
            SecretKey key;
            ASN1ObjectIdentifier algorithm = algorithmIdentifier.getAlgorithm();

            try
            {
                if (algorithm.on(PKCSObjectIdentifiers.pkcs_12PbeIds))
                {
                    PKCS12PBEParams pbeParams = PKCS12PBEParams.getInstance(algorithmIdentifier.getParameters());

                    cipher = helper.createCipher(algorithm.getId());

                    cipher.init(Cipher.DECRYPT_MODE, new PKCS12KeyWithParameters(password, wrongPKCS12Zero, pbeParams.getIV(), pbeParams.getIterations().intValue()));

                    encryptionAlg = algorithmIdentifier;
                }
                else if (algorithm.equals(PKCSObjectIdentifiers.id_PBES2))
                {
                    PBES2Parameters alg = PBES2Parameters.getInstance(algorithmIdentifier.getParameters());
                    PBKDF2Params func = PBKDF2Params.getInstance(alg.getKeyDerivationFunc().getParameters());
                    AlgorithmIdentifier encScheme = AlgorithmIdentifier.getInstance(alg.getEncryptionScheme());

                    SecretKeyFactory keyFact = helper.createSecretKeyFactory(alg.getKeyDerivationFunc().getAlgorithm().getId());

                    if (func.isDefaultPrf())
                    {
                        key = keyFact.generateSecret(new PBEKeySpec(password, func.getSalt(), func.getIterationCount().intValue(), keySizeProvider.getKeySize(encScheme)));
                    }
                    else
                    {
                        key = keyFact.generateSecret(new PBKDF2KeySpec(password, func.getSalt(), func.getIterationCount().intValue(), keySizeProvider.getKeySize(encScheme), func.getPrf()));
                    }

                    cipher = helper.createCipher(alg.getEncryptionScheme().getAlgorithm().getId());

                    encryptionAlg = AlgorithmIdentifier.getInstance(alg.getEncryptionScheme());

                    ASN1Encodable encParams = alg.getEncryptionScheme().getParameters();
                    if (encParams instanceof ASN1OctetString)
                    {
                        cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(ASN1OctetString.getInstance(encParams).getOctets()));
                    }
                    else
                    {
                        // TODO: at the moment it's just GOST, but...
                        GOST28147Parameters gParams = GOST28147Parameters.getInstance(encParams);

                        cipher.init(Cipher.DECRYPT_MODE, key, new GOST28147ParameterSpec(gParams.getEncryptionParamSet(), gParams.getIV()));
                    }
                }
            }
            catch (Exception e)
            {
                throw new OperatorCreationException("unable to create InputDecryptor: " + e.getMessage(), e);
            }

            return new InputDecryptor()
            {
                public AlgorithmIdentifier getAlgorithmIdentifier()
                {
                    return encryptionAlg;
                }

                public InputStream getInputStream(InputStream input)
                {
                    return new CipherInputStream(input, cipher);
                }
            };
        }
    };
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:81,代码来源:JcePKCSPBEInputDecryptorProviderBuilder.java


示例4: build

import org.bouncycastle.asn1.pkcs.PBES2Parameters; //导入依赖的package包/类
public OutputEncryptor build(final char[] password)
    throws OperatorCreationException
{
    final Cipher cipher;
    SecretKey key;

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

    final AlgorithmIdentifier encryptionAlg;
    final byte[] salt = new byte[20];

    random.nextBytes(salt);

    try
    {
        if (algorithm.on(PKCSObjectIdentifiers.pkcs_12PbeIds))
        {
            cipher = helper.createCipher(algorithm.getId());

            cipher.init(Cipher.ENCRYPT_MODE, new PKCS12KeyWithParameters(password, salt, iterationCount));

            encryptionAlg = new AlgorithmIdentifier(algorithm, new PKCS12PBEParams(salt, iterationCount));
        }
        else if (algorithm.equals(PKCSObjectIdentifiers.id_PBES2))
        {
            SecretKeyFactory keyFact = helper.createSecretKeyFactory(PKCSObjectIdentifiers.id_PBKDF2.getId());

            key = keyFact.generateSecret(new PBEKeySpec(password, salt, iterationCount, keySizeProvider.getKeySize(new AlgorithmIdentifier(keyEncAlgorithm))));

            cipher = helper.createCipher(keyEncAlgorithm.getId());

            cipher.init(Cipher.ENCRYPT_MODE, key, random);

            PBES2Parameters algParams = new PBES2Parameters(
                               new KeyDerivationFunc(PKCSObjectIdentifiers.id_PBKDF2, new PBKDF2Params(salt, iterationCount)),
                               new EncryptionScheme(keyEncAlgorithm, ASN1Primitive.fromByteArray(cipher.getParameters().getEncoded())));

            encryptionAlg = new AlgorithmIdentifier(algorithm, algParams);
        }
        else
        {
            throw new OperatorCreationException("unrecognised algorithm");
        }

        return new OutputEncryptor()
        {
            public AlgorithmIdentifier getAlgorithmIdentifier()
            {
                return encryptionAlg;
            }

            public OutputStream getOutputStream(OutputStream out)
            {
                return new CipherOutputStream(out, cipher);
            }

            public GenericKey getKey()
            {
                if (isPKCS12(encryptionAlg.getAlgorithm()))
                {
                    return new GenericKey(encryptionAlg, PKCS5PasswordToBytes(password));
                }
                else
                {
                    return new GenericKey(encryptionAlg, PKCS12PasswordToBytes(password));
                }
            }
        };
    }
    catch (Exception e)
    {
        throw new OperatorCreationException("unable to create OutputEncryptor: " + e.getMessage(), e);
    }
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:78,代码来源:JcePKCSPBEOutputEncryptorBuilder.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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