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


Java CMSAlgorithm类代码示例

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


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

示例1: encrypt

import org.bouncycastle.cms.CMSAlgorithm; //导入依赖的package包/类
private byte[] encrypt(byte[] data) throws CertificateEncodingException,
		CMSException, IOException {
	CMSEnvelopedDataGenerator cmsEnvelopedDataGenerator = new CMSEnvelopedDataGenerator();
	for (X509Certificate destinationCertificate : this.destinationCertificates) {
		cmsEnvelopedDataGenerator
				.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(
						destinationCertificate)
						.setProvider(BouncyCastleProvider.PROVIDER_NAME));
	}
	CMSTypedData cmsTypedData = new CMSProcessableByteArray(data);
	CMSEnvelopedData cmsEnvelopedData = cmsEnvelopedDataGenerator.generate(
			cmsTypedData,
			new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC)
					.setProvider(BouncyCastleProvider.PROVIDER_NAME)
					.build());
	return cmsEnvelopedData.getEncoded();
}
 
开发者ID:e-Contract,项目名称:mycarenet,代码行数:18,代码来源:Sealer.java

示例2: testEncryptedValue

import org.bouncycastle.cms.CMSAlgorithm; //导入依赖的package包/类
public void testEncryptedValue()
    throws Exception
{
    KeyPairGenerator kGen = KeyPairGenerator.getInstance("RSA", BC);

    kGen.initialize(512);

    KeyPair kp = kGen.generateKeyPair();
    X509Certificate cert = makeV1Certificate(kp, "CN=Test", kp, "CN=Test");

    JcaEncryptedValueBuilder build = new JcaEncryptedValueBuilder(new JceAsymmetricKeyWrapper(cert.getPublicKey()).setProvider(BC), new JceCRMFEncryptorBuilder(CMSAlgorithm.AES128_CBC).setProvider(BC).build());
    EncryptedValue value = build.build(cert);
    ValueDecryptorGenerator decGen = new JceAsymmetricValueDecryptorGenerator(kp.getPrivate()).setProvider(BC);

    // try direct
    encryptedValueParserTest(value, decGen, cert);

    // try indirect
    encryptedValueParserTest(EncryptedValue.getInstance(value.getEncoded()), decGen, cert);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:21,代码来源:AllTests.java

示例3: testEncryptedValuePassphrase

import org.bouncycastle.cms.CMSAlgorithm; //导入依赖的package包/类
public void testEncryptedValuePassphrase()
    throws Exception
{
    char[] passphrase = PASSPHRASE.toCharArray();
    KeyPairGenerator kGen = KeyPairGenerator.getInstance("RSA", BC);

    kGen.initialize(512);

    KeyPair kp = kGen.generateKeyPair();
    X509Certificate cert = makeV1Certificate(kp, "CN=Test", kp, "CN=Test");

    EncryptedValueBuilder build = new EncryptedValueBuilder(new JceAsymmetricKeyWrapper(cert.getPublicKey()).setProvider(BC), new JceCRMFEncryptorBuilder(CMSAlgorithm.AES128_CBC).setProvider(BC).build());
    EncryptedValue value = build.build(passphrase);
    ValueDecryptorGenerator decGen = new JceAsymmetricValueDecryptorGenerator(kp.getPrivate()).setProvider(BC);

    // try direct
    encryptedValuePassphraseParserTest(value, null, decGen, cert);

    // try indirect
    encryptedValuePassphraseParserTest(EncryptedValue.getInstance(value.getEncoded()), null, decGen, cert);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:22,代码来源:AllTests.java

示例4: testECMQVKeyAgree

import org.bouncycastle.cms.CMSAlgorithm; //导入依赖的package包/类
public void testECMQVKeyAgree()
    throws Exception
{
    byte[] data = Hex.decode("504b492d4320434d5320456e76656c6f706564446174612053616d706c65");

    CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();

    edGen.addRecipientInfoGenerator(new JceKeyAgreeRecipientInfoGenerator(CMSAlgorithm.ECMQV_SHA1KDF,
        _origEcKP.getPrivate(), _origEcKP.getPublic(),
        CMSAlgorithm.AES128_WRAP).addRecipient(_reciEcCert).setProvider(BC));

    CMSEnvelopedData ed = edGen.generate(
        new CMSProcessableByteArray(data),
        new BcCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC).build());

    assertEquals(ed.getEncryptionAlgOID(), CMSAlgorithm.AES128_CBC.getId());

    RecipientInformationStore recipients = ed.getRecipientInfos();

    confirmDataReceived(recipients, data, _reciEcCert, _reciEcKP.getPrivate(), BC);
    confirmNumberRecipients(recipients, 1);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:23,代码来源:BcEnvelopedDataTest.java

示例5: testECKeyAgree

import org.bouncycastle.cms.CMSAlgorithm; //导入依赖的package包/类
public void testECKeyAgree()
    throws Exception
{
    byte[] data = Hex.decode("504b492d4320434d5320456e76656c6f706564446174612053616d706c65");

    CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();

    edGen.addRecipientInfoGenerator(new JceKeyAgreeRecipientInfoGenerator(CMSAlgorithm.ECDH_SHA1KDF,
        _origEcKP.getPrivate(), _origEcKP.getPublic(),
         CMSAlgorithm.AES128_WRAP).addRecipient(_reciEcCert).setProvider(BC));

    CMSEnvelopedData ed = edGen.generate(
        new CMSProcessableByteArray(data),
        new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC).setProvider(BC).build());

    assertEquals(ed.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.AES128_CBC);

    RecipientInformationStore recipients = ed.getRecipientInfos();

    confirmDataReceived(recipients, data, _reciEcCert, _reciEcKP.getPrivate(), BC);
    confirmNumberRecipients(recipients, 1);
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:23,代码来源:NewEnvelopedDataTest.java

示例6: testECMQVKeyAgree

import org.bouncycastle.cms.CMSAlgorithm; //导入依赖的package包/类
public void testECMQVKeyAgree()
    throws Exception
{
    byte[] data = Hex.decode("504b492d4320434d5320456e76656c6f706564446174612053616d706c65");

    CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();

    edGen.addRecipientInfoGenerator(new JceKeyAgreeRecipientInfoGenerator(CMSAlgorithm.ECMQV_SHA1KDF,
        _origEcKP.getPrivate(), _origEcKP.getPublic(),
        CMSAlgorithm.AES128_WRAP).addRecipient(_reciEcCert).setProvider(BC));

    CMSEnvelopedData ed = edGen.generate(
        new CMSProcessableByteArray(data),
        new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC).setProvider(BC).build());

    assertEquals(ed.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.AES128_CBC);

    RecipientInformationStore recipients = ed.getRecipientInfos();

    confirmDataReceived(recipients, data, _reciEcCert, _reciEcKP.getPrivate(), BC);
    confirmNumberRecipients(recipients, 1);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:23,代码来源:NewEnvelopedDataTest.java

示例7: testEncryptedValuePassphraseWithPadding

import org.bouncycastle.cms.CMSAlgorithm; //导入依赖的package包/类
public void testEncryptedValuePassphraseWithPadding()
    throws Exception
{
    char[] passphrase = PASSPHRASE.toCharArray();
    KeyPairGenerator kGen = KeyPairGenerator.getInstance("RSA", BC);

    kGen.initialize(512);

    KeyPair kp = kGen.generateKeyPair();
    X509Certificate cert = makeV1Certificate(kp, "CN=Test", kp, "CN=Test");

    FixedLengthMGF1Padder mgf1Padder = new FixedLengthMGF1Padder(200, new SecureRandom());
    EncryptedValueBuilder build = new EncryptedValueBuilder(new JceAsymmetricKeyWrapper(cert.getPublicKey()).setProvider(BC), new JceCRMFEncryptorBuilder(CMSAlgorithm.AES128_CBC).setProvider(BC).build(), mgf1Padder);
    EncryptedValue value = build.build(passphrase);
    ValueDecryptorGenerator decGen = new JceAsymmetricValueDecryptorGenerator(kp.getPrivate()).setProvider(BC);

    // try direct
    encryptedValuePassphraseParserTest(value, mgf1Padder, decGen, cert);

    // try indirect
    encryptedValuePassphraseParserTest(EncryptedValue.getInstance(value.getEncoded()), mgf1Padder, decGen, cert);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:23,代码来源:AllTests.java

示例8: init

import org.bouncycastle.cms.CMSAlgorithm; //导入依赖的package包/类
private void init(ASN1ObjectIdentifier keyAgreementOID)
    throws CMSException
{
    if (random == null)
    {
        random = new SecureRandom();
    }

    if (keyAgreementOID.equals(CMSAlgorithm.ECMQV_SHA1KDF))
    {
        if (ephemeralKP == null)
        {
                throw new CMSException(
                    "cannot determine MQV ephemeral key pair parameters from public key");
        }
    }
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:18,代码来源:JceKeyAgreeRecipientInfoGenerator.java

示例9: testHeaders

import org.bouncycastle.cms.CMSAlgorithm; //导入依赖的package包/类
public void testHeaders()
    throws Exception
{
    MimeBodyPart    msg      = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington");

    SMIMEEnvelopedGenerator  gen = new SMIMEEnvelopedGenerator();
      
    gen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC));
     
    //
    // generate a MimeBodyPart object which encapsulates the content
    // we want encrypted.
    //

    MimeBodyPart mp = gen.generate(msg, new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC).setProvider(BC).build());

    assertEquals("application/pkcs7-mime; name=\"smime.p7m\"; smime-type=enveloped-data", mp.getHeader("Content-Type")[0]);
    assertEquals("attachment; filename=\"smime.p7m\"", mp.getHeader("Content-Disposition")[0]);
    assertEquals("S/MIME Encrypted Message", mp.getHeader("Content-Description")[0]);
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:21,代码来源:NewSMIMEEnvelopedTest.java

示例10: testECKeyAgree

import org.bouncycastle.cms.CMSAlgorithm; //导入依赖的package包/类
public void testECKeyAgree()
    throws Exception
{
    byte[] data = Hex.decode("504b492d4320434d5320456e76656c6f706564446174612053616d706c65");

    CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();

    edGen.addRecipientInfoGenerator(new JceKeyAgreeRecipientInfoGenerator(CMSAlgorithm.ECDH_SHA1KDF,
        _origEcKP.getPrivate(), _origEcKP.getPublic(),
         CMSAlgorithm.AES128_WRAP).addRecipient(_reciEcCert).setProvider(BC));

    CMSEnvelopedData ed = edGen.generate(
        new CMSProcessableByteArray(data),
        new BcCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC).build());

    assertEquals(ed.getEncryptionAlgOID(), CMSAlgorithm.AES128_CBC.getId());

    RecipientInformationStore recipients = ed.getRecipientInfos();

    confirmDataReceived(recipients, data, _reciEcCert, _reciEcKP.getPrivate(), BC);
    confirmNumberRecipients(recipients, 1);
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:23,代码来源:BcEnvelopedDataTest.java

示例11: init

import org.bouncycastle.cms.CMSAlgorithm; //导入依赖的package包/类
private void init(ASN1ObjectIdentifier keyAgreementOID)
    throws CMSException
{
    if (random == null)
    {
        random = new SecureRandom();
    }

    if (keyAgreementOID.equals(CMSAlgorithm.ECMQV_SHA1KDF))
    {
        if (ephemeralKP == null)
        {
            try
            {
                ECParameterSpec ecParamSpec = ((ECPublicKey)senderPublicKey).getParams();

                KeyPairGenerator ephemKPG = helper.createKeyPairGenerator(keyAgreementOID);

                ephemKPG.initialize(ecParamSpec, random);

                ephemeralKP = ephemKPG.generateKeyPair();
            }
            catch (InvalidAlgorithmParameterException e)
            {
                throw new CMSException(
                    "cannot determine MQV ephemeral key pair parameters from public key: " + e);
            }
        }
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:31,代码来源:JceKeyAgreeRecipientInfoGenerator.java

示例12: tryKekAlgorithm

import org.bouncycastle.cms.CMSAlgorithm; //导入依赖的package包/类
private void tryKekAlgorithm(SecretKey kek, DERObjectIdentifier algOid)
    throws NoSuchAlgorithmException, NoSuchProviderException, CMSException
{
    byte[]    data = "WallaWallaWashington".getBytes();
    CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();

    byte[]  kekId = new byte[] { 1, 2, 3, 4, 5 };

    edGen.addRecipientInfoGenerator(new JceKEKRecipientInfoGenerator(kekId, kek).setProvider(BC));

    CMSEnvelopedData ed = edGen.generate(
                            new CMSProcessableByteArray(data),
                            new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC).setProvider(BC).build());

    RecipientInformationStore recipients = ed.getRecipientInfos();

    Collection c = recipients.getRecipients();
    Iterator it = c.iterator();

    assertEquals(ed.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.DES_EDE3_CBC);

    if (it.hasNext())
    {
        RecipientInformation recipient = (RecipientInformation)it.next();

        assertEquals(algOid.getId(), recipient.getKeyEncryptionAlgOID());

        byte[] recData = recipient.getContent(new JceKEKEnvelopedRecipient(kek).setProvider(BC));

        assertTrue(Arrays.equals(data, recData));
    }
    else
    {
        fail("no recipient found");
    }
}
 
开发者ID:mlundblad,项目名称:bc-java,代码行数:37,代码来源:NewEnvelopedDataTest.java

示例13: tryKekAlgorithm

import org.bouncycastle.cms.CMSAlgorithm; //导入依赖的package包/类
private void tryKekAlgorithm(BcSymmetricKeyWrapper kekWrapper, BcSymmetricKeyUnwrapper kekUnwrapper, ASN1ObjectIdentifier algOid)
    throws NoSuchAlgorithmException, NoSuchProviderException, CMSException
{
    byte[]    data = "WallaWallaWashington".getBytes();
    CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();

    byte[]  kekId = new byte[] { 1, 2, 3, 4, 5 };

    edGen.addRecipientInfoGenerator(new BcKEKRecipientInfoGenerator(kekId, kekWrapper));

    CMSEnvelopedData ed = edGen.generate(
                            new CMSProcessableByteArray(data),
                            new BcCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC).build());

    RecipientInformationStore recipients = ed.getRecipientInfos();

    Collection c = recipients.getRecipients();
    Iterator it = c.iterator();

    assertEquals(ed.getEncryptionAlgOID(), CMSAlgorithm.DES_EDE3_CBC.getId());

    if (it.hasNext())
    {
        RecipientInformation recipient = (RecipientInformation)it.next();

        assertEquals(algOid.getId(), recipient.getKeyEncryptionAlgOID());

        byte[] recData = recipient.getContent(new BcKEKEnvelopedRecipient(kekUnwrapper));

        assertTrue(Arrays.equals(data, recData));
    }
    else
    {
        fail("no recipient found");
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:37,代码来源:BcEnvelopedDataTest.java

示例14: testECMQVKeyAgreeMultiple

import org.bouncycastle.cms.CMSAlgorithm; //导入依赖的package包/类
public void testECMQVKeyAgreeMultiple()
    throws Exception
{
    byte[] data = Hex.decode("504b492d4320434d5320456e76656c6f706564446174612053616d706c65");

    CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();

    JceKeyAgreeRecipientInfoGenerator recipientGenerator = new JceKeyAgreeRecipientInfoGenerator(CMSAlgorithm.ECMQV_SHA1KDF,
        _origEcKP.getPrivate(), _origEcKP.getPublic(), CMSAlgorithm.AES128_WRAP).setProvider(BC);

    recipientGenerator.addRecipient(_reciEcCert);
    recipientGenerator.addRecipient(_reciEcCert2);

    edGen.addRecipientInfoGenerator(recipientGenerator);

    CMSEnvelopedData ed = edGen.generate(
        new CMSProcessableByteArray(data),
        new BcCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC).build());

    assertEquals(ed.getEncryptionAlgOID(), CMSAlgorithm.AES128_CBC.getId());

    RecipientInformationStore recipients = ed.getRecipientInfos();

    confirmDataReceived(recipients, data, _reciEcCert, _reciEcKP.getPrivate(), BC);
    confirmDataReceived(recipients, data, _reciEcCert2, _reciEcKP2.getPrivate(), BC);
    confirmNumberRecipients(recipients, 2);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:28,代码来源:BcEnvelopedDataTest.java

示例15: testOriginatorInfo

import org.bouncycastle.cms.CMSAlgorithm; //导入依赖的package包/类
public void testOriginatorInfo()
    throws Exception
{
    CMSEnvelopedData env = new CMSEnvelopedData(CMSSampleMessages.originatorMessage);

    RecipientInformationStore  recipients = env.getRecipientInfos();

    assertEquals(CMSAlgorithm.DES_EDE3_CBC.getId(), env.getEncryptionAlgOID());
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:10,代码来源:BcEnvelopedDataTest.java


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