• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java PKMACBuilder类的典型用法和代码示例

java 2次浏览

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

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

示例1: testMacProtectedMessage

点赞 3

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

    kGen.initialize(512);

    KeyPair kp = kGen.generateKeyPair();
    X509CertificateHolder cert = makeV3Certificate(kp, "CN=Test", kp, "CN=Test");

    GeneralName sender = new GeneralName(new X500Name("CN=Sender"));
    GeneralName recipient = new GeneralName(new X500Name("CN=Recip"));

    ProtectedPKIMessage message = new ProtectedPKIMessageBuilder(sender, recipient)
                                              .setBody(new PKIBody(PKIBody.TYPE_INIT_REP, CertRepMessage.getInstance(new DERSequence(new DERSequence()))))
                                              .addCMPCertificate(cert)
                                              .build(new PKMACBuilder(new JcePKMACValuesCalculator().setProvider(BC)).build("secret".toCharArray()));

    PKMACBuilder pkMacBuilder = new PKMACBuilder(new JcePKMACValuesCalculator().setProvider(BC));

    assertTrue(message.verify(pkMacBuilder, "secret".toCharArray()));

    assertEquals(sender, message.getHeader().getSender());
    assertEquals(recipient, message.getHeader().getRecipient());
}
 

开发者ID:credentials,
项目名称:irma_future_id,
代码行数:26,
代码来源:AllTests.java

示例2: verify

点赞 2

import org.bouncycastle.cert.crmf.PKMACBuilder; //导入依赖的package包/类
/**
 * Verify a message with password based MAC protection.
 *
 * @param pkMacBuilder MAC builder that can be used to construct the appropriate MacCalculator
 * @param password the MAC password
 * @return true if the passed in password and MAC builder verify the message, false otherwise.
 * @throws CMPException if algorithm not MAC based, or an exception is thrown verifying the MAC.
 */
public boolean verify(PKMACBuilder pkMacBuilder, char[] password)
    throws CMPException
{
    if (!CMPObjectIdentifiers.passwordBasedMac.equals(pkiMessage.getHeader().getProtectionAlg().getAlgorithm()))
    {
        throw new CMPException("protection algorithm not mac based");
    }

    try
    {
        pkMacBuilder.setParameters(PBMParameter.getInstance(pkiMessage.getHeader().getProtectionAlg().getParameters()));
        MacCalculator calculator = pkMacBuilder.build(password);

        OutputStream macOut = calculator.getOutputStream();

        ASN1EncodableVector v = new ASN1EncodableVector();

        v.add(pkiMessage.getHeader());
        v.add(pkiMessage.getBody());

        macOut.write(new DERSequence(v).getEncoded(ASN1Encoding.DER));

        macOut.close();

        return Arrays.areEqual(calculator.getMac(), pkiMessage.getProtection().getBytes());
    }
    catch (Exception e)
    {
        throw new CMPException("unable to verify MAC: " + e.getMessage(), e);
    }
}
 

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

示例3: testProofOfPossessionWithoutSender

点赞 2

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

    kGen.initialize(512);

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

    JcaCertificateRequestMessageBuilder certReqBuild = new JcaCertificateRequestMessageBuilder(BigInteger.ONE);

    certReqBuild.setPublicKey(kp.getPublic())
                .setAuthInfoPKMAC(new PKMACBuilder(new JcePKMACValuesCalculator()), "fred".toCharArray())
                .setProofOfPossessionSigningKeySigner(new JcaContentSignerBuilder("SHA1withRSA").setProvider(BC).build(kp.getPrivate()));

    certReqBuild.addControl(new JcaPKIArchiveControlBuilder(kp.getPrivate(), new X500Principal("CN=test"))
                                  .addRecipientGenerator(new JceKeyTransRecipientInfoGenerator(cert).setProvider(BC))
                                  .build(new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier(CMSEnvelopedDataGenerator.AES128_CBC)).setProvider(BC).build()));

    JcaCertificateRequestMessage certReqMsg = new JcaCertificateRequestMessage(certReqBuild.build().getEncoded());

    // check that internal check on popo signing is working okay
    try
    {
        certReqMsg.isValidSigningKeyPOP(new JcaContentVerifierProviderBuilder().setProvider(BC).build(kp.getPublic()));
        fail("IllegalStateException not thrown");
    }
    catch (IllegalStateException e)
    {
        // ignore
    }

    assertTrue(certReqMsg.isValidSigningKeyPOP(new JcaContentVerifierProviderBuilder().setProvider(BC).build(kp.getPublic()), new PKMACBuilder(new JcePKMACValuesCalculator().setProvider(BC)), "fred".toCharArray()));

    assertEquals(kp.getPublic(), certReqMsg.getPublicKey());
}
 

开发者ID:credentials,
项目名称:irma_future_id,
代码行数:38,
代码来源:AllTests.java

示例4: testProofOfPossessionWithSender

点赞 2

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

    kGen.initialize(512);

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

    JcaCertificateRequestMessageBuilder certReqBuild = new JcaCertificateRequestMessageBuilder(BigInteger.ONE);

    certReqBuild.setPublicKey(kp.getPublic())
                .setAuthInfoSender(new X500Principal("CN=Test"))
                .setProofOfPossessionSigningKeySigner(new JcaContentSignerBuilder("SHA1withRSA").setProvider(BC).build(kp.getPrivate()));

    certReqBuild.addControl(new JcaPKIArchiveControlBuilder(kp.getPrivate(), new X500Principal("CN=test"))
                                  .addRecipientGenerator(new JceKeyTransRecipientInfoGenerator(cert).setProvider(BC))
                                  .build(new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier(CMSEnvelopedDataGenerator.AES128_CBC)).setProvider(BC).build()));

    JcaCertificateRequestMessage certReqMsg = new JcaCertificateRequestMessage(certReqBuild.build().getEncoded());

    // check that internal check on popo signing is working okay
    try
    {
        certReqMsg.isValidSigningKeyPOP(new JcaContentVerifierProviderBuilder().setProvider(BC).build(kp.getPublic()), new PKMACBuilder(new JcePKMACValuesCalculator().setProvider(BC)), "fred".toCharArray());

        fail("IllegalStateException not thrown");
    }
    catch (IllegalStateException e)
    {
        // ignore
    }


    assertTrue(certReqMsg.isValidSigningKeyPOP(new JcaContentVerifierProviderBuilder().setProvider(BC).build(kp.getPublic())));

    assertEquals(kp.getPublic(), certReqMsg.getPublicKey());
}
 

开发者ID:credentials,
项目名称:irma_future_id,
代码行数:40,
代码来源:AllTests.java

示例5: testSampleCr

点赞 2

import org.bouncycastle.cert.crmf.PKMACBuilder; //导入依赖的package包/类
public void testSampleCr()
    throws Exception
{
    PKIMessage msg = loadMessage("sample_cr.der");
    ProtectedPKIMessage procMsg = new ProtectedPKIMessage(new GeneralPKIMessage(msg));

    assertTrue(procMsg.verify(new PKMACBuilder(new JcePKMACValuesCalculator().setProvider(BC)), "TopSecret1234".toCharArray()));
}
 

开发者ID:credentials,
项目名称:irma_future_id,
代码行数:9,
代码来源:AllTests.java

示例6: testProofOfPossessionWithoutSender

点赞 2

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

    kGen.initialize(512);

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

    JcaCertificateRequestMessageBuilder certReqBuild = new JcaCertificateRequestMessageBuilder(BigInteger.ONE);

    certReqBuild.setPublicKey(kp.getPublic())
                .setAuthInfoPKMAC(new PKMACBuilder(new JcePKMACValuesCalculator()), "fred".toCharArray())
                .setProofOfPossessionSigningKeySigner(new JcaContentSignerBuilder("SHA1withRSA").setProvider(BC).build(kp.getPrivate()));

    certReqBuild.addControl(new JcaPKIArchiveControlBuilder(kp.getPrivate(), new X500Name("CN=test"))
                                  .addRecipientGenerator(new JceKeyTransRecipientInfoGenerator(cert).setProvider(BC))
                                  .build(new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier(CMSEnvelopedDataGenerator.AES128_CBC)).setProvider(BC).build()));

    JcaCertificateRequestMessage certReqMsg = new JcaCertificateRequestMessage(certReqBuild.build());

    // check that internal check on popo signing is working okay
    try
    {
        certReqMsg.isValidSigningKeyPOP(new JcaContentVerifierProviderBuilder().setProvider(BC).build(kp.getPublic()));
        fail("IllegalStateException not thrown");
    }
    catch (IllegalStateException e)
    {
        // ignore
    }

    assertTrue(certReqMsg.isValidSigningKeyPOP(new JcaContentVerifierProviderBuilder().setProvider(BC).build(kp.getPublic()), new PKMACBuilder(new JcePKMACValuesCalculator().setProvider(BC)), "fred".toCharArray()));

    assertEquals(kp.getPublic(), certReqMsg.getPublicKey());
}
 

开发者ID:credentials,
项目名称:irma_future_id,
代码行数:38,
代码来源:AllTests.java

示例7: testProofOfPossessionWithSender

点赞 2

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

    kGen.initialize(512);

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

    JcaCertificateRequestMessageBuilder certReqBuild = new JcaCertificateRequestMessageBuilder(BigInteger.ONE);

    certReqBuild.setPublicKey(kp.getPublic())
                .setAuthInfoSender(new X500Name("CN=Test"))
                .setProofOfPossessionSigningKeySigner(new JcaContentSignerBuilder("SHA1withRSA").setProvider(BC).build(kp.getPrivate()));

    certReqBuild.addControl(new JcaPKIArchiveControlBuilder(kp.getPrivate(), new X500Name("CN=test"))
                                  .addRecipientGenerator(new JceKeyTransRecipientInfoGenerator(cert).setProvider(BC))
                                  .build(new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier(CMSEnvelopedDataGenerator.AES128_CBC)).setProvider(BC).build()));

    JcaCertificateRequestMessage certReqMsg = new JcaCertificateRequestMessage(certReqBuild.build());

    // check that internal check on popo signing is working okay
    try
    {
        certReqMsg.isValidSigningKeyPOP(new JcaContentVerifierProviderBuilder().setProvider(BC).build(kp.getPublic()), new PKMACBuilder(new JcePKMACValuesCalculator().setProvider(BC)), "fred".toCharArray());

        fail("IllegalStateException not thrown");
    }
    catch (IllegalStateException e)
    {
        // ignore
    }


    assertTrue(certReqMsg.isValidSigningKeyPOP(new JcaContentVerifierProviderBuilder().setProvider(BC).build(kp.getPublic())));

    assertEquals(kp.getPublic(), certReqMsg.getPublicKey());
}
 

开发者ID:credentials,
项目名称:irma_future_id,
代码行数:40,
代码来源:AllTests.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)