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


Java PKCS12PBEParams类代码示例

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


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

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

示例4: isMacValid

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入依赖的package包/类
/**
 * Verify the MacData attached to the PFX is consistent with what is expected.
 *
 * @param macCalcProviderBuilder provider builder for the calculator for the MAC
 * @param password password to use
 * @return true if mac data is valid, false otherwise.
 * @throws PKCSException if there is a problem evaluating the MAC.
 * @throws IllegalStateException if no MAC is actually present
 */
public boolean isMacValid(PKCS12MacCalculatorBuilderProvider macCalcProviderBuilder, char[] password)
    throws PKCSException
{
    if (hasMac())
    {
        MacData pfxmData = pfx.getMacData();
        MacDataGenerator mdGen = new MacDataGenerator(macCalcProviderBuilder.get(new AlgorithmIdentifier(pfxmData.getMac().getAlgorithmId().getAlgorithm(), new PKCS12PBEParams(pfxmData.getSalt(), pfxmData.getIterationCount().intValue()))));

        try
        {
            MacData mData = mdGen.build(
                password,
                ASN1OctetString.getInstance(pfx.getAuthSafe().getContent()).getOctets());

            return Arrays.constantTimeAreEqual(mData.getEncoded(), pfx.getMacData().getEncoded());
        }
        catch (IOException e)
        {
            throw new PKCSException("unable to process AuthSafe: " + e.getMessage());
        }
    }

    throw new IllegalStateException("no MAC present on PFX");
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:34,代码来源:PKCS12PfxPdu.java

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

示例6: createMacCalculator

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

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

示例8: engineInit

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入依赖的package包/类
protected void engineInit(
    AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException
{
    if (!(paramSpec instanceof PBEParameterSpec))
    {
        throw new InvalidParameterSpecException("PBEParameterSpec required to initialise a PKCS12 PBE parameters algorithm parameters object");
    }

    PBEParameterSpec pbeSpec = (PBEParameterSpec)paramSpec;

    this.params = new PKCS12PBEParams(pbeSpec.getSalt(),
        pbeSpec.getIterationCount());
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:15,代码来源:PBEPKCS12.java

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

示例10: build

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入依赖的package包/类
public MacCalculator build(final char[] password)
{
    if (random == null)
    {
        random = new SecureRandom();
    }

    byte[] salt = new byte[saltLength];

    random.nextBytes(salt);

    return PKCS12PBEUtils.createMacCalculator(algorithmIdentifier.getAlgorithm(), digest, new PKCS12PBEParams(salt, iterationCount), password);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:14,代码来源:BcPKCS12MacCalculatorBuilder.java

示例11: build

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入依赖的package包/类
public OutputEncryptor build(final char[] password)
{
    if (random == null)
    {
        random = new SecureRandom();
    }

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

    random.nextBytes(salt);

    final PKCS12PBEParams pbeParams = new PKCS12PBEParams(salt, iterationCount);

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

    engine.init(true, params);

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

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

        public GenericKey getKey()
        {
            return new GenericKey(new AlgorithmIdentifier(algorithm, pbeParams), PKCS12ParametersGenerator.PKCS12PasswordToBytes(password));
        }
    };
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:36,代码来源:BcPKCS12PBEOutputEncryptorBuilder.java

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

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

示例14: build

import org.bouncycastle.asn1.pkcs.PKCS12PBEParams; //导入依赖的package包/类
public OutputEncryptor build(final char[] password)
{
    if (random == null)
    {
        random = new SecureRandom();
    }

    final byte[] salt = new byte[20];
    final int    iterationCount = 1024;

    random.nextBytes(salt);

    final PKCS12PBEParams pbeParams = new PKCS12PBEParams(salt, iterationCount);

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

    engine.init(true, params);

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

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

        public GenericKey getKey()
        {
            return new GenericKey(new AlgorithmIdentifier(algorithm, pbeParams), PKCS12ParametersGenerator.PKCS12PasswordToBytes(password));
        }
    };
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:37,代码来源:BcPKCS12PBEOutputEncryptorBuilder.java


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