我有一个用于创建加密电子邮件的电子邮件应用程序。它在Outlook中运行良好,我发送电子邮件的所有电子邮件交易对手都没有问题报告。 但是,当我尝试使用Mimekit解密它时,我得到一个“错误数据”异常。
一些堆栈跟踪:
at System.Security.Cryptography.Pkcs.EnvelopedCms.DecryptContent(RecipientInfoCollection recipientInfos, X509Certificate2Collection extraStore)
at System.Security.Cryptography.Pkcs.EnvelopedCms.Decrypt()
at MimeKit.Cryptography.WindowsSecure...
我的电子邮件mime看起来像这样:
Received: from Dx ([x]) by
x ([x]) with mapi id
x; Fri, 7 Mar 2014 14:48:49 +0100
From: x <x@x.com>
To: x <x2@x.com>
Subject:
xxxxxxxx
07-03-2014 14:48:46
Thread-Topic:
xxxxxxx
07-03-2014 14:48:46
Thread-Index: AQHPOgv3JHiUE6wuJk+EQu4eAA1oDA==
Date: Fri, 7 Mar 2014 14:48:48 +0100
Message-ID: <x>
Accept-Language: da-DK, en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: x
X-MS-Exchange-Organization-AuthMechanism: x
X-MS-Exchange-Organization-AuthSource: x
X-MS-Has-Attach: yes
X-MS-Exchange-Organization-SCL: -1
X-MS-TNEF-Correlator:
Content-Type: application/pkcs7-mime; name="smime.p7m";
smime-type=enveloped-data
Content-Disposition: attachment; filename="smime.p7m"
Content-Transfer-Encoding: base64
MIME-Version: 1.0
MIIeOgYJKoZIhvcNAQcDoIIeKzCCHicCAQAxggLnMIIC4wIBADCByjCBxDEfMB0GA1UEChMWRGFu
c2tlIENvbW1vZGl0aWVzIEEvUzEaMBgGA1UECxMRQnVzaW5lc3MgU29mdHdhcmUxNTAzBgkqhkiG
9w0BCQEWJmJ1c2luZXNzY2xlYXJpbmdAZGFuc2tlY29tbW9kaXRpZXMuY29tMQ8wDQYDVQQHEwZB
YXJodXMxEDAOBgNVBAgTB0Rlbm1hcmsxCzAJBgNVBAYTAkRLMR4wHAYDVQQDExVkYW5za2Vjb21t
b2RpdGllcy5jb20CAQEwDQYJKoZIhvc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J2Pxrmcc7tCWdnVOjglp3JcUBL2ZRJeQBPk5Bm6OCczR+sviFux2Me
MF/3E7TSRspBPscL9XHHH8eBznnjZ8fJAu0YAhTGjzL1DOjjVZ9KNlxWwGG+mCALm+XU8DpJNKg9
Nuq2uYSRu4p5K4+lEAyRM2cdiPLVcDuGKQpBGQnhsB6DslLImiYXSzy6OcHIsUf4kyAGes5tsBxR
i1IfNHcW4G/7i4VUy+530PqA0+TECNkpgiGxrevWk0gF0NgD+DDNgDzZRjJaRpMx0ufbP9twVvv+
6J/meqKiykYcU/NUYV/TuNiERKrOOWZs697IyY/g3nPWHZurZXJbmk9MpND2wn5PZzRTx7qyBVfn
nenl/WtSVMmKA4D1dLnHoeN1hoAyQgrfqS4yymL26UemhCXIV87hAYwwoAbpfr4=
这是我执行加密的方式:
public static string EncryptContent(string content, X509Certificate2 certificate)
{
byte[] contentBytes = Encoding.ASCII.GetBytes(content);
var envelopedCms = new EnvelopedCms(SubjectIdentifierType.IssuerAndSerialNumber, new ContentInfo(contentBytes));
var recipient = new CmsRecipient(SubjectIdentifierType.IssuerAndSerialNumber, certificate);
envelopedCms.Encrypt(recipient);
var encodedData = envelopedCms.Encode();
var encodedDataBase64 = Convert.ToBase64String(encodedData, Base64FormattingOptions.InsertLineBreaks);
return encodedDataBase64;
}
这就是我尝试解密的方式:
var primarySecureMimeContext = CreateSecureMimeContext(certificateInfo.PrimaryCertificate,
certificateInfo.PrimaryPassword);
var primaryDecryptedEntity = entity.Decrypt(primarySecureMimeContext);
private SecureMimeContext CreateSecureMimeContext(string certificateFilename, string certificatePassword)
{
var secureMimeContext = new WindowsSecureMimeContext();
var certificate = new X509Certificate2(certificateFilename,
certificatePassword);
var bouncyX509Certificate = Org.BouncyCastle.Security.DotNetUtilities.FromX509Certificate(certificate);
secureMimeContext.Import(bouncyX509Certificate);
return secureMimeContext;
}
当我直接使用封装的cms解密内容时,没有问题。
这是我自己解密后的电子邮件:
Content-Type: multipart/mixed;
boundary="5511bd79-26dc-41e5-ac96-7adfdea5f6e5"
--5511bd79-26dc-41e5-ac96-7adfdea5f6e5
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
--5511bd79-26dc-41e5-ac96-7adfdea5f6e5
Content-Type: application/octet-stream;
name="TestFile.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="TestFile.txt"
77u/VGVlZWVlZXN0
--5511bd79-26dc-41e5-ac96-7adfdea5f6e5--
任何人都可以看到导致这种情况的原因吗?
使用jstedfast建议的DummySecureMimeContext后,它可以工作。可以在此处找到更全面的演练:https://github.com/jstedfast/MimeKit/issues/38
答案 0 :(得分:1)
我认为问题在于您将证书添加到上下文中的方式:
private SecureMimeContext CreateSecureMimeContext(string certificateFilename, string certificatePassword)
{
var secureMimeContext = new WindowsSecureMimeContext();
var certificate = new X509Certificate2(certificateFilename,
certificatePassword);
var bouncyX509Certificate = Org.BouncyCastle.Security.DotNetUtilities.FromX509Certificate(certificate);
secureMimeContext.Import(bouncyX509Certificate);
return secureMimeContext;
}
这样做是将证书添加到AddressBook证书存储区,但是您实际想要添加它以便解密它(因为您还需要私钥密码)是个人证书存储区。 / p>
试试这个:
private SecureMimeContext CreateSecureMimeContext (string certificateFilename, string certificatePassword)
{
var secureMimeContext = new WindowsSecureMimeContext ();
using (var stream = File.OpenRead (certificateFilename))
secureMimeContext.Import (stream, certificatePassword);
return secureMimeContext;
}
您获得的异常消息不是很有帮助,但我猜这意味着它无法找到证书和/或私钥。我写了一个测试程序并且没有成功再现这个bug,所以我可能是错的......但由于我的证书/私钥已经导入我的个人证书库,我不知道如何删除它们来测试这个理论
让我知道这对你有用。
更新:哎呀,我做错了。刚刚更新了上面的CreateSecureMimeContext()以打开证书文件流,因为WindowsSecureMimeContext.Import()接受流而不是文件名。