.NET Framework Bookmark and Share   
 index > .NET Base Class Library > Setting pin programmatically for CmsSigner object
 

Setting pin programmatically for CmsSigner object

Hi,I'm trying to use SignedCms -object to sign messages. I 'm using certificate stored on smart card and don't want to prompt dialog for user to set PIN (because program will run on server). here's code I'm using:

byte[] buffer = "test data to sign";

ContentInfo contentInfo = new ContentInfo(buffer);
SignedCms signedCms = new SignedCms(contentInfo);

CspParameters cspparams = new CspParameters(1,"Personal CSP");
System.Security.SecureString pwstr = new System.Security.SecureString();
pwstr.AppendChar('1');
pwstr.AppendChar('2');
pwstr.AppendChar('3');
pwstr.AppendChar('4');
pwstr.AppendChar('5');
cspparams.KeyPassword = pwstr;
cspparams.Flags = CspProviderFlags.NoPrompt;

CmsSigner cmsSigner = new CmsSigner(cspparams);
cmsSigner.Certificate = m_X509Certificate;

// Sign the CMS/PKCS #7 message.
try {
signedCms.ComputeSignature(cmsSigner, true);
}
// Encode the CMS/PKCS #7 message.
byte[] signature = signedCms.Encode();

Now the problem is that initializing of CmsSigner object throws an CryptographicException with message "bad key". Code works fine if I replace line
CmsSigner cmsSigner = new CmsSigner(cspparams);
with
CmsSigner cmsSigner = new CmsSigner(m_X509Certificate).

Only then it prompts PIN dialog. I believe there must be easy solution for this, but just can't find it.. So I would like to know if my way is even correct way to try to set PIN programmatically?

Thanks in advance,
-Juksa

ps. I know quite similar topics exists allready, but those didn't help me.
juksa

There is another thread that dicusses it, there is a reported bug in the .Net framework.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=148433&SiteID=1

Regards,

David Hernández Díez

David Hernández Díez

There is another thread that dicusses it, there is a reported bug in the .Net framework.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=148433&SiteID=1

Regards,

David Hernández Díez

David Hernández Díez

Juksa,

Were you ever to get the problem solved?

If so can you let me know where to look as we are experiencing the same problem with VS2005 and framework 2.0

Thanks in advance.

Nick

N Adams

Hi Juksa

do you have found the solution? I have the same issue but no reply to fix it.

Could you help?

Thank in advance

Henri

hbouzagl

You can use google to search for other answers

Custom Search

More Threads

• Can C# help you determine inheritance?
• ActiveX and Application Domain
• ProcessStartInfo.WorkingDirectory Ignored
• Search for COM Server.
• problem in date convertion
• Breaking a loop over string arrays
• Problem with Reflction
• Creating an Encryption DLL
• To watch the C: and D: folders activity and to monitor SW installation and uninstallation on my PC
• How to cryptography file PDF