use of org.nhindirect.stagent.cert.X509CertificateEx in project nhin-d by DirectProject.
the class CryptographerTest method testEncryptWithSingleCert_wrongDecryptCert_assertFailDecrypt.
public void testEncryptWithSingleCert_wrongDecryptCert_assertFailDecrypt() throws Exception {
X509Certificate cert = TestUtils.getExternalCert("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("altnameonly");
boolean exceptionOccured = false;
try {
cryptographer.decrypt(encEntity, certex);
} catch (NHINDException e) {
if (e.getError().equals(MimeError.Unexpected))
;
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
Aggregations