简体   繁体   中英

MimeKit encrypt Message with AES

I want du encrypt and sign a mail with MimeKit.

Generating the Message works:

        CmsRecipient CmsRecipient = new CmsRecipient("mail.cer");
        CmsRecipient.EncryptionAlgorithms = new EncryptionAlgorithm[] { EncryptionAlgorithm.Aes192 };
        to1.Add(CmsRecipient);

        var signed = MultipartSigned.Create(ctx, signer, multipart);
        var encrypted = ApplicationPkcs7Mime.Encrypt(ctx, to1, signed);
        message.Body = MultipartSigned.Create(ctx, signer, encrypted);

In Outlook they arrive encrypted with: 168 Bit 3DES But I need AES 265. How can I manage this?

I can set signing to RSA/SHA512 with

        signer.DigestAlgorithm = DigestAlgorithm.Sha512;

but not the encryption.

Edit: Updated to my Solution

The CmsSigner specifies the DigestAlgorithm, but it's the CmsRecipient that specifies which encryption algorithm(s) that the recipient supports.

The way that the encryption algorithm is chosen by MimeKit is that it figures out the best encryption algorithm supported by each recipient and then uses that.

In other words, if you are encrypting to 5 recipients and all of them support AES256, then MimeKit will use AES256. But if one of the recipients only supports, for example, 3DES (and all of the other recipients also support 3DES as well as AES256), then 3DES is chosen instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM