Unable to send encrypted E-Mail

I want to send encrypted E-Mails via Aspose.

I have used encrpyt() method along with the public key path as shown below:

MailMessage eMsg = originalMsg.encrypt(Files.readAllBytes(publicCertFilePath), “’”);

isEncrypted() returns true and I assume that the encryption works.

But the problem is when I send the E-Mail using SmtpClient client.send() method, I get the following error:

class com.aspose.email.SmtpException: Failure sending mail. —> class com.aspose.email.system.exceptions.InvalidOperationException: Operation is not valid due to the current state of the object.

How do I resolve this issue?

@arne411,

Thank you for writing to Aspose support team.

This issue is observed and logged under Id:EMAILNET-39002 for detailed analysis. You will be automatically notified once any update is available in this regard.

Hey,

Is there any progress on this issue?

best regards

Arne

@arne411,

The issue is still under investigation and we’ll update you here once a fix version is available for download.

Hi,

Is there any progress on this issue?

best regards

Arne

@arne411,

We investigated this at our end and were not able to reproduce it using the latest version of the API. Please try it with the latest version and if the issue still persists, please share your certificate files with us for further investigation at our end.

Hi,

I tried the latest version of API and as you said, I do not receive the InvalidOperationException anymore while calling client.send(). Encryption seems to be working. But there is another problem when I tried to decrypt as follows:

MailMessage dMsg = eMsg.decrypt(Files.readAllBytes(privateCertFilePath), “password”);

Now I again receive the same InvalidOperationException while calling the decrypt() method.

Please find attached the certificate files in the zip file.

Certificate_files.zip (4.3 KB)

Could you point out if something is missing and why this exception occurs?

best regards

Arne

@arne411

We have tested this issue with provided security certificates and found the following exception while decryption:

System.Security.Cryptography.CryptographicException: 'The enveloped-data message does not contain the specified recipient.

We are working on this issue and you will automatically be informed here once we have more information to share.

@arne411

We have tested this issue with provided security certificates and found that the provided public/private key pair is not a match.

However, we have tested the code sample with our public/private key pair and it works correctly. So it is requested to kindly check certificates.

Moreover, certificate exported from PFX also works fine.

openssl pkcs12 -in certificate.pfx -out exp_my_certificate.crt -nokeys -clcerts
openssl x509 -inform pem -in exp_my_certificate.crt -outform der -out exp_my_certificate.cer

Hi,

This issue is solved when I used another security certificate.

Thanks and Regards,
Arne

@arne411,

Thank you for the updates. Can we close the issue now then?

Hi,

Yes, you could close the issue.

Thanks and Regards,
Arne

@arne411,

You are very welcome.

The issues you have found earlier (filed as EMAILNET-39002) have been fixed in this update.