Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to sign my emails - generated by a MailMessage class - with a DKIM signature from MimeKit - but got the error "Private key not found." in the line "
DkimSigner signer = new DkimSigner(stream, "my-site.dk", "dkim")
" And I don't know why :-( I have checked that the file with the private key exists.
I have searched and googlet everything until now - but with no success :-(

Therefore I kindly ask for help.

Best regards,
Michael

What I have tried:

I have tried to compose a signing with DKIM in this way:
var message = MimeMessage.CreateFromMailMessage(mail);

HeaderId[] headers = new HeaderId[] { HeaderId.From, HeaderId.Subject, HeaderId.Date };
DkimCanonicalizationAlgorithm headerAlgorithm = DkimCanonicalizationAlgorithm.Relaxed;
DkimCanonicalizationAlgorithm bodyAlgorithm = DkimCanonicalizationAlgorithm.Relaxed;

MemoryStream stream = new MemoryStream(File.ReadAllBytes("C:\\DKIM\\dkim.my-site.dk.pem"));
DkimSigner signer = new DkimSigner(stream, "my-site.dk", "dkim")
{
    SignatureAlgorithm = DkimSignatureAlgorithm.RsaSha256,
    AgentOrUserIdentifier = "@my-site.dk",
    QueryMethod = "dns/txt",
};
Posted
Updated 28-Jun-21 23:31pm
v5

1 solution

You've checked that the file exists, but the error message says that the file does not contain a private key.

A PEM file[^] can contain a private key, a public key, or both. If it doesn't contain a private key, then you cannot use it to sign your message.

There are various free tools you can use to decode your PEM file - for example: Report URI: PEM Decoder[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900