Search in sources :

Example 1 with RecipientInformation

use of org.bouncycastle.cms.RecipientInformation in project nhin-d by DirectProject.

the class DefaultDirectRecipientInformationFactory_createInstanceTest method testInstanceTest_emptyProvider_assertDefaultProvider.

public void testInstanceTest_emptyProvider_assertDefaultProvider() throws Exception {
    final SMIMEEnveloped env = createSMIMEEnv();
    final RecipientInformation recipient = (RecipientInformation) env.getRecipientInfos().getRecipients().iterator().next();
    final DefaultDirectRecipientInformationFactory factory = new DefaultDirectRecipientInformationFactory();
    final DefaultDirectRecipientInformation recInfo = (DefaultDirectRecipientInformation) factory.createInstance(recipient, env);
    assertEquals(CryptoExtensions.getJCEProviderName(), recInfo.encProvider);
}
Also used : RecipientInformation(org.bouncycastle.cms.RecipientInformation) SMIMEEnveloped(org.bouncycastle.mail.smime.SMIMEEnveloped)

Example 2 with RecipientInformation

use of org.bouncycastle.cms.RecipientInformation in project nhin-d by DirectProject.

the class DefaultDirectRecipientInformationFactory_createInstanceTest method testInstanceTest_configedProvider_assertConfigedProvider.

public void testInstanceTest_configedProvider_assertConfigedProvider() throws Exception {
    final SMIMEEnveloped env = createSMIMEEnv();
    final RecipientInformation recipient = (RecipientInformation) env.getRecipientInfos().getRecipients().iterator().next();
    final DefaultDirectRecipientInformationFactory factory = new DefaultDirectRecipientInformationFactory("Hello");
    final DefaultDirectRecipientInformation recInfo = (DefaultDirectRecipientInformation) factory.createInstance(recipient, env);
    assertEquals("Hello", recInfo.encProvider);
}
Also used : RecipientInformation(org.bouncycastle.cms.RecipientInformation) SMIMEEnveloped(org.bouncycastle.mail.smime.SMIMEEnveloped)

Example 3 with RecipientInformation

use of org.bouncycastle.cms.RecipientInformation in project nhin-d by DirectProject.

the class DefaultDirectRecipientInformation_getDecryptedContentTest method testDecryptedContent_defaultConfig_assertDecrypted.

public void testDecryptedContent_defaultConfig_assertDecrypted() throws Exception {
    final SMIMEEnveloped env = createSMIMEEnv();
    final RecipientInformation recipient = (RecipientInformation) env.getRecipientInfos().getRecipients().iterator().next();
    final SplitDirectRecipientInformationFactory factory = new SplitDirectRecipientInformationFactory();
    final SplitDirectRecipientInformation recInfo = (SplitDirectRecipientInformation) factory.createInstance(recipient, env);
    // this won't work unless the data is successfully decrypted
    assertNotNull(recInfo.getDecryptedContent(encCert.getPrivateKey()));
}
Also used : RecipientInformation(org.bouncycastle.cms.RecipientInformation) SMIMEEnveloped(org.bouncycastle.mail.smime.SMIMEEnveloped)

Example 4 with RecipientInformation

use of org.bouncycastle.cms.RecipientInformation in project nhin-d by DirectProject.

the class SplitDirectRecipientInformationFactory_createInstanceTest method testInstanceTest_emptyProvider_assertDefaultProvider.

public void testInstanceTest_emptyProvider_assertDefaultProvider() throws Exception {
    final SMIMEEnveloped env = createSMIMEEnv();
    final RecipientInformation recipient = (RecipientInformation) env.getRecipientInfos().getRecipients().iterator().next();
    final SplitDirectRecipientInformationFactory factory = new SplitDirectRecipientInformationFactory();
    final SplitDirectRecipientInformation recInfo = (SplitDirectRecipientInformation) factory.createInstance(recipient, env);
    assertEquals(CryptoExtensions.getJCEProviderName(), recInfo.encProvider);
    assertEquals(CryptoExtensions.getJCESensitiveProviderName(), recInfo.keyEncProvider);
}
Also used : RecipientInformation(org.bouncycastle.cms.RecipientInformation) SMIMEEnveloped(org.bouncycastle.mail.smime.SMIMEEnveloped)

Example 5 with RecipientInformation

use of org.bouncycastle.cms.RecipientInformation in project nhin-d by DirectProject.

the class SplitDirectRecipientInformation_getDecryptedContentTest method testGetDecryptedContent_sameDefaultEncAndKeyEncProvider_assertDecrypted.

public void testGetDecryptedContent_sameDefaultEncAndKeyEncProvider_assertDecrypted() throws Exception {
    final SMIMEEnveloped env = createSMIMEEnv();
    final RecipientInformation recipient = (RecipientInformation) env.getRecipientInfos().getRecipients().iterator().next();
    final SplitDirectRecipientInformationFactory factory = new SplitDirectRecipientInformationFactory();
    final SplitDirectRecipientInformation recInfo = (SplitDirectRecipientInformation) factory.createInstance(recipient, env);
    // this will be non-null if it works correctly
    assertNotNull(recInfo.getDecryptedContent(((X509CertificateEx) encCert).getPrivateKey()));
}
Also used : RecipientInformation(org.bouncycastle.cms.RecipientInformation) X509CertificateEx(org.nhindirect.stagent.cert.X509CertificateEx) SMIMEEnveloped(org.bouncycastle.mail.smime.SMIMEEnveloped)

Aggregations

RecipientInformation (org.bouncycastle.cms.RecipientInformation)9 SMIMEEnveloped (org.bouncycastle.mail.smime.SMIMEEnveloped)9 X509CertificateEx (org.nhindirect.stagent.cert.X509CertificateEx)4 Key (java.security.Key)2 KeyStore (java.security.KeyStore)2 PrivateKey (java.security.PrivateKey)2 Certificate (java.security.cert.Certificate)2 X509Certificate (java.security.cert.X509Certificate)2 MutableKeyStoreProtectionManager (org.nhindirect.common.crypto.MutableKeyStoreProtectionManager)1 PKCS11Credential (org.nhindirect.common.crypto.PKCS11Credential)1 BootstrappedPKCS11Credential (org.nhindirect.common.crypto.impl.BootstrappedPKCS11Credential)1 StaticPKCS11TokenKeyStoreProtectionManager (org.nhindirect.common.crypto.impl.StaticPKCS11TokenKeyStoreProtectionManager)1 CacheableKeyStoreManagerCertificateStore (org.nhindirect.stagent.cert.impl.CacheableKeyStoreManagerCertificateStore)1