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


Java PKCS12PBEParams.getIV方法代码示例

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


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

示例3: wrapKey

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入方法依赖的package包/类
protected byte[] wrapKey(
    String algorithm,
    Key key,
    PKCS12PBEParams pbeParams,
    char[] password)
    throws IOException
{
    PBEKeySpec pbeSpec = new PBEKeySpec(password);
    byte[] out;

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

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

        cipher.init(Cipher.WRAP_MODE, keyFact.generateSecret(pbeSpec), defParams);

        out = cipher.wrap(key);
    }
    catch (Exception e)
    {
        throw new IOException("exception encrypting data - " + e.toString());
    }

    return out;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:32,代码来源:PKCS12KeyStoreSpi.java

示例4: wrapKey

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入方法依赖的package包/类
protected byte[] wrapKey(
    String algorithm,
    Key key,
    PKCS12PBEParams pbeParams,
    char[] password)
    throws IOException
{
    PBEKeySpec pbeSpec = new PBEKeySpec(password);
    byte[] out;

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

        Cipher cipher = helper.createCipher(algorithm);

        cipher.init(Cipher.WRAP_MODE, keyFact.generateSecret(pbeSpec), defParams);

        out = cipher.wrap(key);
    }
    catch (Exception e)
    {
        throw new IOException("exception encrypting data - " + e.toString());
    }

    return out;
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:31,代码来源:PKCS12KeyStoreSpi.java

示例5: checkCryptoPermission

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入方法依赖的package包/类
public boolean checkCryptoPermission()
	throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidAlgorithmParameterException,
	InvalidKeySpecException
{
	LOG.debug("Cryptography permission check");

	try
	{
		byte[] iv = new byte[20];
		CertificateUtilities.RANDOM.nextBytes(iv);
		PKCS12PBEParams pbeParams = new PKCS12PBEParams(iv, 1024);
		String algorithm = "1.2.840.113549.1.12.1.3";
		SecretKeyFactory keyFact = SecretKeyFactory.getInstance(algorithm, "BC");
		PBEParameterSpec defParams = new PBEParameterSpec(pbeParams.getIV(), pbeParams.getIterations().intValue());

		Cipher cipher = Cipher.getInstance(algorithm, "BC");
		PBEKeySpec pbeSpec = new PBEKeySpec("testwelcome".toCharArray());
		cipher.init(Cipher.WRAP_MODE, keyFact.generateSecret(pbeSpec), defParams);

		return true;
	} catch (InvalidKeyException ex)
	{
		cryptoPermissionDenied = true;
		setErrorMessage(Messages.getString("MailsterKeyStoreFactory.error.vm.crypto.restrictions"));
		return false;
	}
}
 
开发者ID:edeoliveira,项目名称:Mailster,代码行数:28,代码来源:MailsterKeyStoreFactory.java

示例6: wrapKey

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入方法依赖的package包/类
protected byte[] wrapKey(
    String                  algorithm,
    Key                     key,
    PKCS12PBEParams         pbeParams,
    char[]                  password)
    throws IOException
{
    PBEKeySpec          pbeSpec = new PBEKeySpec(password);
    byte[]              out;

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

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

        cipher.init(Cipher.WRAP_MODE, keyFact.generateSecret(pbeSpec), defParams);

        out = cipher.wrap(key);
    }
    catch (Exception e)
    {
        throw new IOException("exception encrypting data - " + e.toString());
    }

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

示例7: 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

示例8: 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

示例9: 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:mlundblad,项目名称:bc-java,代码行数:40,代码来源:JDKPKCS12KeyStore.java

示例10: 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

示例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


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