use of org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGeneratorFactory in project nhin-d by DirectProject.
the class SMIMECryptographerImpl_createSignatureEntityTest method testCreateSignatureEntity_difSigAndDigestGenerators_assertEntityCreatedAndMatchesControl.
public void testCreateSignatureEntity_difSigAndDigestGenerators_assertEntityCreatedAndMatchesControl() throws Exception {
SplitProviderDirectSignedDataGeneratorFactory factory = new SplitProviderDirectSignedDataGeneratorFactory("SunRsaSign", "BC");
final SMIMECryptographerImpl impl = new SMIMECryptographerImpl();
impl.setSignedDataGeneratorFactory(factory);
final String testMessage = TestUtils.readResource("MultipartMimeMessage.txt");
final MimeEntity ent = new Message(new ByteArrayInputStream(testMessage.getBytes())).extractEntityForSignature(true);
byte[] bytesToSign = EntitySerializer.Default.serializeToBytes(ent);
final X509Certificate sigCertBPrivate = TestUtils.loadCertificate("certCheckB.p12");
final MimeMultipart mm = impl.createSignatureEntity(bytesToSign, Arrays.asList(sigCertBPrivate));
assertNotNull(mm);
assertEquals(2, mm.getCount());
validatedSignatureHeaders(mm);
// now create the control
final SMIMECryptographerImpl controllImpl = new SMIMECryptographerImpl();
final MimeMultipart controllmm = controllImpl.createSignatureEntity(bytesToSign, Arrays.asList(sigCertBPrivate));
assertNotNull(controllmm);
assertEquals(2, controllmm.getCount());
// make sure the signatures match
final MimeEntity signedContent = contentToMimeEntity(mm.getBodyPart(1));
final MimeEntity controlSignedContent = contentToMimeEntity(controllmm.getBodyPart(1));
assertTrue(Arrays.equals(signedContent.getContentAsBytes(), controlSignedContent.getContentAsBytes()));
// verify the signatures
validateSignature(deserializeSignatureEnvelope(mm), sigCertBPrivate);
validateSignature(deserializeSignatureEnvelope(controllmm), sigCertBPrivate);
}
Aggregations