use of org.nhindirect.stagent.cryptography.SignedEntity in project nhin-d by DirectProject.
the class CryptographerTest method testSignMimeEntity_SHA256Digest_forceStrongDigest_assertValidation.
public void testSignMimeEntity_SHA256Digest_forceStrongDigest_assertValidation() throws Exception {
X509CertificateEx certex = TestUtils.getInternalCert("user1");
SMIMECryptographerImpl cryptographer = new SMIMECryptographerImpl();
cryptographer.setDigestAlgorithm(DigestAlgorithm.SHA256);
MimeEntity entity = new MimeEntity();
entity.setText("Hello world.");
entity.setHeader(MimeStandard.ContentTypeHeader, "text/plain");
entity.setHeader(MimeStandard.ContentTransferEncodingHeader, "7bit");
SignedEntity signedEnt = cryptographer.sign(entity, certex);
assertNotNull(signedEnt);
byte[] signedEntityBytes = EntitySerializer.Default.serializeToBytes(signedEnt.getContent());
byte[] entityBytes = EntitySerializer.Default.serializeToBytes(entity);
assertTrue(Arrays.equals(signedEntityBytes, entityBytes));
assertNotNull(signedEnt.getSignature());
X509Certificate cert = TestUtils.getExternalCert("user1");
cryptographer.checkSignature(signedEnt, cert, new ArrayList<X509Certificate>());
}
use of org.nhindirect.stagent.cryptography.SignedEntity in project nhin-d by DirectProject.
the class CryptographerTest method testEncryptAndSignMimeEntity.
public void testEncryptAndSignMimeEntity() throws Exception {
X509Certificate cert = TestUtils.getInternalCACert("user1");
SMIMECryptographerImpl cryptographer = new SMIMECryptographerImpl();
MimeEntity entity = new MimeEntity();
entity.setText("Hello world.");
entity.setHeader(MimeStandard.ContentTypeHeader, "text/plain");
entity.setHeader(MimeStandard.ContentTransferEncodingHeader, "7bit");
MimeEntity encEntity = cryptographer.encrypt(entity, cert);
assertNotNull(encEntity);
X509CertificateEx certex = TestUtils.getInternalCert("user1");
SignedEntity signedEnt = cryptographer.sign(entity, certex);
assertNotNull(signedEnt);
cryptographer.checkSignature(signedEnt, cert, new ArrayList<X509Certificate>());
}
Aggregations