Compose a mail using S/MIME standard and the email must be encrypted using AES-256 and a public key

FaizalSaidaliFaizalSaidali USMember ✭✭
edited September 2018 in General

I have developed a xamarin app to composes a mail using S/MIME standard and the mail must be encrypted using AES-256 algorithm and a public key(.pfx file). I have used MailKit for this. I can send mail but it has failed by the client side. I put my code here. Please assist me to resolve this issue.

                using (var context = new DefaultSecureMimeContext())
                {
                    var certificateFile = Application.Context.Assets.Open("ELD_RSA.pfx");
                    var certificate = new X509Certificate2(ReadFully(certificateFile));

                    var recipientCollection = new CmsRecipientCollection();
                    var bountyRecipientCertificate = DotNetUtilities.FromX509Certificate(certificate);

                    var recipient = new CmsRecipient(bountyRecipientCertificate);
                    recipient.EncryptionAlgorithms = new EncryptionAlgorithm[] { EncryptionAlgorithm.Aes256 };
                    recipientCollection.Add(recipient);

                    message.Body = ApplicationPkcs7Mime.Encrypt(context, recipientCollection, multipart);
                }
Sign In or Register to comment.