Search The ForumSearch   RegisterRegister  LoginLogin

MailBee.NET SMTP

 AfterLogic Forum : MailBee.NET SMTP
Subject Topic: Invalid cryptographic private key format. Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
raindm
Groupie
Groupie
Avatar

Joined: 31 January 2008
Location: Israel
Online Status: Offline
Posts: 44
Posted: 17 September 2009 at 1:25am | IP Logged Quote raindm

Hi

I have an issue with DomainKey.

When i use the byte method to save the domain key private key i get the error:
" Invalid cryptographic private key format. "

The code is:
//Read DomainKey Specifications
       using (Stream stream = new FileStream(@Directory.GetCurrentDirectory() + "\\rsa.private", FileMode.Open, FileAccess.Read))
                        {
                            privateKey = new byte[stream.Length];
                            stream.Read(privateKey, 0, privateKey.Length);
                        }
DomainKeys dk = new DomainKeys();
objMailer.Message = dk.Sign(objMailer.Message, null, privateKey, "alfa");

               
However when i use direct read from file it does work using the code:

DomainKeys dk = new DomainKeys();
   objMailer.Message = dk.Sign(objMailer.Message, null, Directory.GetCurrentDirectory() + "\\rsa.private", true, "alfa");


I do not want to read the file for every mail is send so i prefer to use the byte method for less H.D access.


If you know the reason for this it would greatly helpful.


Thank you,
Dror
Back to Top View raindm's Profile Search for other posts by raindm
 
Andrew
AfterLogic Support
AfterLogic Support


Joined: 28 April 2006
Location: United States
Online Status: Offline
Posts: 1189
Posted: 21 September 2009 at 3:37am | IP Logged Quote Andrew

The developers will investigate this.
Back to Top View Andrew's Profile Search for other posts by Andrew
 
Andrew
AfterLogic Support
AfterLogic Support


Joined: 28 April 2006
Location: United States
Online Status: Offline
Posts: 1189
Posted: 24 September 2009 at 2:39am | IP Logged Quote Andrew

The issue happens because rsa.private file contains the key encoded along with special header, but Sign method expects pure key without irrelevant data.

In case when Sign loads the key from the file, it correctly processes the header and decodes the pure key.

However, the following call should do the trick for you:

Code:
objMailer.Message = dk.Sign(objMailer.Message, null, System.Text.Encoding.ASCII.GetString(privateKey), false, "alfa");



Best regards,
Andrew
Back to Top View Andrew's Profile Search for other posts by Andrew
 
raindm
Groupie
Groupie
Avatar

Joined: 31 January 2008
Location: Israel
Online Status: Offline
Posts: 44
Posted: 27 September 2009 at 3:07am | IP Logged Quote raindm

thank you very much, it seems to work fine..!

Back to Top View raindm's Profile Search for other posts by raindm
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide