简体   繁体   English

无法解析 Mimekit 中的消息头错误

[英]Failed to parse message headers error in Mimekit

I've encountered an error Failed to parse message headers after executing MimeMessage.Load please see the code below:我遇到了执行MimeMessage.LoadFailed to parse message headers的错误,请参见下面的代码:

public MimeEntity decryptString(string responseString)
       {
            responseString = "MIME - Version: 1.0 \n"+
                            "Content - Disposition: attachment; filename =\'smime.p7m\' \n" +
                            "Content - Type: application / pkcs7 - mime; smime - type = enveloped - data; name =\'smime.p7m\' \n"+
                            "Content - Transfer - Encoding: base64 \n\n" + responseString;

            byte[] Msg = Encoding.ASCII.GetBytes(responseString);
            MemoryStream mm = new MemoryStream(Msg);
            MimeMessage responseMessage = MimeMessage.Load(mm);


            string filename = HttpContext.Current.Request.PhysicalApplicationPath + "/Certificates/1608104889.txt";

            var message = new MimeMessage();
            message.Subject = Path.GetFileNameWithoutExtension(filename);
            message.Date = DateTimeOffset.Now;
            message.Body = responseMessage.Body;



            var pkcs7 = message.Body as ApplicationPkcs7Mime;

            if (pkcs7 != null && pkcs7.SecureMimeType == SecureMimeType.EnvelopedData)
            {
                // the top-level MIME part of the message is encrypted using S/MIME
                return pkcs7.Decrypt();
            }
            else
            {
                // the top-level MIME part is not encrypted
                return message.Body;
            }

Here is the value of responseString before executing Encoding.ASCII.GetBytes :这是执行Encoding.ASCII.GetBytes之前responseString的值:

MIME - Version: 1.0 
Content - Disposition: attachment; filename ='smime.p7m' 
Content - Type: application / pkcs7 - mime; smime - type = enveloped - data; name ='smime.p7m' 
Content - Transfer - Encoding: base64 

MIIB8AYJKoZIhvcNAQcDoIIB4TCCAd0CAQAxggFAMIIBPAIBADAkMBYxFDASBgNVBAMTC1NpbmFwdElRIENBAgoeg+bBAAAAAAAMMA0GCSqGSIb3DQEBAQUABIIBAIlcT4+v5h69Rh17Edz/6h08PZAG63xfWDw3JkAET0MLqgmGlZTDeUOukLiZuC3Oahy4o3NaWH0LQMGmsaO14HKkxoxsLmMEVCLD2MfJO1seIC2tjQcZBXGWNyYYq4B6cbqYuK3t5KJtLebU8a1ep46tEDoqNRSgeb7+T3/AbMq6K9vi+vkIJ7s/aMY6gHjTbPhaTytZ5EeM4kiwA6mr1E8zUSQ26i6HqdVhxpqyV1AjXrXsZWxD0uTR+QrJzmSlXA9l1ghd5pEyUObvxl8yX2f8KvUW9BKfZYqpzNz060jD2v4v4zih88RYtvrpIs43ZojgMMoq9aWulV9hfZmY9v4wgZMGCSqGSIb3DQEHATAUBggqhkiG9w0DBwQIW7kUs2r/kxqAcMy+kMFM9YbnLJynANOlH6/DauuSUncDsqWhgf9fksm/0RYNlwp3qAjbYkxp1DLeR2AUr0ESZxG6mSKIPnRSwcO1wRJnZBBzloyo926naZ1aL+tz3RtNNXXtkNtz9ps4ldxMCrETh6wmiL6L99vpY7s=

What I wanted to do here is to decrypt the content of a MIME Response in string format from an API to be able to use its data.我在这里要做的是从 API 中以字符串格式解密 MIME 响应的内容,以便能够使用其数据。 I'm only new to using MimeKit.我只是使用 MimeKit 的新手。 If anyone knows how can I do this it will be a great help.如果有人知道我该怎么做,那将是一个很大的帮助。

Header names cannot contain spaces. Header 名称不能包含空格。

MIME - Version: -> MIME-Version: MIME - Version: -> MIME-Version:

Content - Disposition: -> Content-Disposition: Content - Disposition: -> Content-Disposition:

Content - Type: -> Content-Type: Content - Type: - > Content-Type:

Content - Transfer - Encoding: -> Content-Transfer-Encoding: Content - Transfer - Encoding: -> Content-Transfer-Encoding:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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