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


Java PKCS12PBEParams.getInstance方法代码示例

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


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

示例1: cryptData

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入方法依赖的package包/类
protected byte[] cryptData(
    boolean forEncryption,
    AlgorithmIdentifier algId,
    char[] password,
    boolean wrongPKCS12Zero,
    byte[] data)
    throws IOException
{
    String algorithm = algId.getAlgorithm().getId();
    PKCS12PBEParams pbeParams = PKCS12PBEParams.getInstance(algId.getParameters());
    PBEKeySpec pbeSpec = new PBEKeySpec(password);

    try
    {
        SecretKeyFactory keyFact = SecretKeyFactory.getInstance(algorithm, bcProvider);
        PBEParameterSpec defParams = new PBEParameterSpec(
            pbeParams.getIV(),
            pbeParams.getIterations().intValue());
        BCPBEKey key = (BCPBEKey)keyFact.generateSecret(pbeSpec);

        key.setTryWrongPKCS12Zero(wrongPKCS12Zero);

        Cipher cipher = Cipher.getInstance(algorithm, bcProvider);
        int mode = forEncryption ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE;
        cipher.init(mode, key, defParams);
        return cipher.doFinal(data);
    }
    catch (Exception e)
    {
        throw new IOException("exception decrypting data - " + e.toString());
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:33,代码来源:PKCS12KeyStoreSpi.java

示例2: get

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入方法依赖的package包/类
public PKCS12MacCalculatorBuilder get(final AlgorithmIdentifier algorithmIdentifier)
{
    return new PKCS12MacCalculatorBuilder()
    {
        public MacCalculator build(final char[] password)
            throws OperatorCreationException
        {
            PKCS12PBEParams pbeParams = PKCS12PBEParams.getInstance(algorithmIdentifier.getParameters());

            return PKCS12PBEUtils.createMacCalculator(algorithmIdentifier.getAlgorithm(), digestProvider.get(algorithmIdentifier), pbeParams, password);
        }

        public AlgorithmIdentifier getDigestAlgorithmIdentifier()
        {
            return new AlgorithmIdentifier(algorithmIdentifier.getAlgorithm(), DERNull.INSTANCE);
        }
    };
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:19,代码来源:BcPKCS12MacCalculatorBuilderProvider.java

示例3: build

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入方法依赖的package包/类
public InputDecryptorProvider build(final char[] password)
{
    return new InputDecryptorProvider()
    {
        public InputDecryptor get(final AlgorithmIdentifier algorithmIdentifier)
        {
            final PaddedBufferedBlockCipher engine = PKCS12PBEUtils.getEngine(algorithmIdentifier.getAlgorithm());

            PKCS12PBEParams           pbeParams = PKCS12PBEParams.getInstance(algorithmIdentifier.getParameters());

            CipherParameters params = PKCS12PBEUtils.createCipherParameters(algorithmIdentifier.getAlgorithm(), digest, engine.getBlockSize(), pbeParams, password);

            engine.init(false, params);

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

                public InputStream getInputStream(InputStream input)
                {
                    return new CipherInputStream(input, engine);
                }

                public GenericKey getKey()
                {
                    return new GenericKey(PKCS12ParametersGenerator.PKCS12PasswordToBytes(password));
                }
            };
        }
    };

}
 
开发者ID:Appdome,项目名称:ipack,代码行数:36,代码来源:BcPKCS12PBEInputDecryptorProviderBuilder.java

示例4: build

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入方法依赖的package包/类
public MacData build(char[] password, byte[] data)
    throws PKCSException
{
    MacCalculator     macCalculator;

    try
    {
        macCalculator = builder.build(password);

        OutputStream out = macCalculator.getOutputStream();

        out.write(data);

        out.close();
    }
    catch (Exception e)
    {
        throw new PKCSException("unable to process data: " + e.getMessage(), e);
    }

    AlgorithmIdentifier algId = macCalculator.getAlgorithmIdentifier();

    DigestInfo dInfo = new DigestInfo(builder.getDigestAlgorithmIdentifier(), macCalculator.getMac());
    PKCS12PBEParams params = PKCS12PBEParams.getInstance(algId.getParameters());

    return new MacData(dInfo, params.getIV(), params.getIterations().intValue());
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:28,代码来源:MacDataGenerator.java

示例5: engineInit

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入方法依赖的package包/类
protected void engineInit(
    byte[] params) 
    throws IOException
{
    ASN1InputStream        aIn = new ASN1InputStream(params);

    this.params = PKCS12PBEParams.getInstance(aIn.readObject());
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:9,代码来源:JDKAlgorithmParameters.java

示例6: unwrapKey

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入方法依赖的package包/类
protected PrivateKey unwrapKey(
    AlgorithmIdentifier   algId,
    byte[]                data,
    char[]                password,
    boolean               wrongPKCS12Zero)
    throws IOException
{
    String              algorithm = algId.getAlgorithm().getId();
    PKCS12PBEParams     pbeParams = PKCS12PBEParams.getInstance(algId.getParameters());

    PBEKeySpec          pbeSpec = new PBEKeySpec(password);
    PrivateKey          out;

    try
    {
        SecretKeyFactory    keyFact = SecretKeyFactory.getInstance(
                                            algorithm, bcProvider);
        PBEParameterSpec    defParams = new PBEParameterSpec(
                                            pbeParams.getIV(),
                                            pbeParams.getIterations().intValue());

        SecretKey           k = keyFact.generateSecret(pbeSpec);
        
        ((BCPBEKey)k).setTryWrongPKCS12Zero(wrongPKCS12Zero);

        Cipher cipher = Cipher.getInstance(algorithm, bcProvider);

        cipher.init(Cipher.UNWRAP_MODE, k, defParams);

        // we pass "" as the key algorithm type as it is unknown at this point
        out = (PrivateKey)cipher.unwrap(data, "", Cipher.PRIVATE_KEY);
    }
    catch (Exception e)
    {
        throw new IOException("exception unwrapping private key - " + e.toString());
    }

    return out;
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:40,代码来源:JDKPKCS12KeyStore.java

示例7: cryptData

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入方法依赖的package包/类
protected byte[] cryptData(
    boolean               forEncryption,
    AlgorithmIdentifier   algId,
    char[]                password,
    boolean               wrongPKCS12Zero,
    byte[]                data)
    throws IOException
{
    String          algorithm = algId.getObjectId().getId();
    PKCS12PBEParams pbeParams = PKCS12PBEParams.getInstance(algId.getParameters());
    PBEKeySpec      pbeSpec = new PBEKeySpec(password);

    try
    {
        SecretKeyFactory keyFact = SecretKeyFactory.getInstance(algorithm, bcProvider);
        PBEParameterSpec defParams = new PBEParameterSpec(
            pbeParams.getIV(),
            pbeParams.getIterations().intValue());
        BCPBEKey key = (BCPBEKey) keyFact.generateSecret(pbeSpec);

        key.setTryWrongPKCS12Zero(wrongPKCS12Zero);

        Cipher cipher = Cipher.getInstance(algorithm, bcProvider);
        int mode = forEncryption ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE;
        cipher.init(mode, key, defParams);
        return cipher.doFinal(data);
    }
    catch (Exception e)
    {
        throw new IOException("exception decrypting data - " + e.toString());
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:33,代码来源:JDKPKCS12KeyStore.java

示例8: unwrapKey

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入方法依赖的package包/类
protected PrivateKey unwrapKey(
    AlgorithmIdentifier   algId,
    byte[]                data,
    char[]                password,
    boolean               wrongPKCS12Zero)
    throws IOException
{
    String              algorithm = algId.getObjectId().getId();
    PKCS12PBEParams     pbeParams = PKCS12PBEParams.getInstance(algId.getParameters());

    PBEKeySpec          pbeSpec = new PBEKeySpec(password);
    PrivateKey          out;

    try
    {
        SecretKeyFactory    keyFact = SecretKeyFactory.getInstance(
                                            algorithm, bcProvider);
        PBEParameterSpec    defParams = new PBEParameterSpec(
                                            pbeParams.getIV(),
                                            pbeParams.getIterations().intValue());

        SecretKey           k = keyFact.generateSecret(pbeSpec);
        
        ((BCPBEKey)k).setTryWrongPKCS12Zero(wrongPKCS12Zero);

        Cipher cipher = Cipher.getInstance(algorithm, bcProvider);

        cipher.init(Cipher.UNWRAP_MODE, k, defParams);

        // we pass "" as the key algorithm type as it is unknown at this point
        out = (PrivateKey)cipher.unwrap(data, "", Cipher.PRIVATE_KEY);
    }
    catch (Exception e)
    {
        throw new IOException("exception unwrapping private key - " + e.toString());
    }

    return out;
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:40,代码来源:JDKPKCS12KeyStore.java

示例9: get

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入方法依赖的package包/类
public PKCS12MacCalculatorBuilder get(final AlgorithmIdentifier algorithmIdentifier)
{
    return new PKCS12MacCalculatorBuilder()
    {
        public MacCalculator build(final char[] password)
            throws OperatorCreationException
        {
            final PKCS12PBEParams pbeParams = PKCS12PBEParams.getInstance(algorithmIdentifier.getParameters());

            try
            {
                final ASN1ObjectIdentifier algorithm = algorithmIdentifier.getAlgorithm();

                final Mac mac = helper.createMac(algorithm.getId());

                SecretKeyFactory keyFact = helper.createSecretKeyFactory(algorithm.getId());
                PBEParameterSpec defParams = new PBEParameterSpec(pbeParams.getIV(), pbeParams.getIterations().intValue());
                PBEKeySpec pbeSpec = new PBEKeySpec(password);
                SecretKey key = keyFact.generateSecret(pbeSpec);

                mac.init(key, defParams);

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

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

                    public byte[] getMac()
                    {
                        return mac.doFinal();
                    }

                    public GenericKey getKey()
                    {
                        return new GenericKey(getAlgorithmIdentifier(), PKCS12ParametersGenerator.PKCS12PasswordToBytes(password));
                    }
                };
            }
            catch (Exception e)
            {
                throw new OperatorCreationException("unable to create MAC calculator: " + e.getMessage(), e);
            }
        }

        public AlgorithmIdentifier getDigestAlgorithmIdentifier()
        {
            return new AlgorithmIdentifier(algorithmIdentifier.getAlgorithm(), DERNull.INSTANCE);
        }
    };
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:58,代码来源:JcePKCS12MacCalculatorBuilderProvider.java

示例10: engineInit

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入方法依赖的package包/类
protected void engineInit(
    byte[] params)
    throws IOException
{
    this.params = PKCS12PBEParams.getInstance(ASN1Primitive.fromByteArray(params));
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:7,代码来源:PBEPKCS12.java

示例11: get

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入方法依赖的package包/类
public PKCS12MacCalculatorBuilder get(final AlgorithmIdentifier algorithmIdentifier)
{
    return new PKCS12MacCalculatorBuilder()
    {
        public MacCalculator build(final char[] password)
            throws OperatorCreationException
        {
            final PKCS12PBEParams pbeParams = PKCS12PBEParams.getInstance(algorithmIdentifier.getParameters());

            try
            {
                final ASN1ObjectIdentifier algorithm = algorithmIdentifier.getAlgorithm();

                final Mac mac = helper.createMac(algorithm.getId());

                PBEParameterSpec defParams = new PBEParameterSpec(pbeParams.getIV(), pbeParams.getIterations().intValue());

                final SecretKey key = new PKCS12Key(password);

                mac.init(key, defParams);

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

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

                    public byte[] getMac()
                    {
                        return mac.doFinal();
                    }

                    public GenericKey getKey()
                    {
                        return new GenericKey(getAlgorithmIdentifier(), key.getEncoded());
                    }
                };
            }
            catch (Exception e)
            {
                throw new OperatorCreationException("unable to create MAC calculator: " + e.getMessage(), e);
            }
        }

        public AlgorithmIdentifier getDigestAlgorithmIdentifier()
        {
            return new AlgorithmIdentifier(algorithmIdentifier.getAlgorithm(), DERNull.INSTANCE);
        }
    };
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:57,代码来源:JcePKCS12MacCalculatorBuilderProvider.java

示例12: build

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入方法依赖的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


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