using System.Text;
namespace ConsoleApp116
{
internal class Program
{
static void Main(string[] args)
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
using (var msg = new MsgReader.Outlook.Storage.Message(@"Message from smime1 to smime2 (encrypted).msg"))
{
var from = msg.Sender;
var sentOn = msg.SentOn;
var recipientsTo = msg.GetEmailRecipients(MsgReader.Outlook.RecipientType.To, false, false);
var recipientsCc = msg.GetEmailRecipients(MsgReader.Outlook.RecipientType.Cc, false, false);
var subject = msg.Subject;
var htmlBody = msg.BodyHtml;
// etc...
}
}
}
}
Expected behavior
It can be read without exception thrown if there is an applicable situation including having a corresponding private key.
Screenshots
Unhandled exception. System.Security.Cryptography.CryptographicException: Invalid cryptographic message type.
at System.Security.Cryptography.Pkcs.SignedCms.<Decode>g__CopyContent|26_0(ReadOnlySpan`1 encodedMessage)
at System.Security.Cryptography.Pkcs.SignedCms.Decode(ReadOnlySpan`1 encodedMessage)
at System.Security.Cryptography.Pkcs.SignedCms.Decode(Byte[] encodedMessage)
at MsgReader.Outlook.Storage.Message.ProcessSignedContent(Byte[] data)
at MsgReader.Outlook.Storage.Message.LoadEncryptedAndPossibleSignedMessage(CFStorage storage)
at MsgReader.Outlook.Storage.Message.LoadStorage(CFStorage storage)
at MsgReader.Outlook.Storage..ctor(String storageFilePath, FileAccess fileAccess)
at MsgReader.Outlook.Storage.Message..ctor(String msgfile, FileAccess fileAccess)
at ConsoleApp116.Program.Main(String[] args) in H:\Proj\ConsoleApp116\ConsoleApp116\Program.cs:line 11
H:\Proj\ConsoleApp116\ConsoleApp116\bin\Debug\net8.0\ConsoleApp116.exe (プロセス 32748) は、コード -532462766 で終了しました。
このウィンドウを閉じるには、任意のキーを押してください...
Desktop (please complete the following information):
OS: Windows 10 Pro (Japanese)
Browser: Google Chrome
Version: 127.0.6533.100
Additional context
The other day, in my GitHub repository, I received a question about how to deal with smime.p7m file.
At that time, I didn't know how to decode it. So I studied about it.
And then I created a complete set of S/MIME sample data at my repository for future research.
Because this MSGReader project seems to contain decryption code, I have tested it.
Describe the bug It throws an exception when I try to load the encrypted msg file by using
new MsgReader.Outlook.Storage.Message(...)
.To Reproduce As one repro sample, I have confirmed this behavior on Windows 10 with C# .NET 8.0 code:
ConsoleApp116.csproj
Program.cs
Expected behavior
It can be read without exception thrown if there is an applicable situation including having a corresponding private key.
Screenshots
Desktop (please complete the following information):
Additional context
The other day, in my GitHub repository, I received a question about how to deal with
smime.p7m
file. At that time, I didn't know how to decode it. So I studied about it. And then I created a complete set of S/MIME sample data at my repository for future research. Because this MSGReader project seems to contain decryption code, I have tested it.