Click here to Skip to main content
15,907,910 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Automatic Properties on .NET 2.0 Pin
Thomas Stockwell6-Apr-08 3:43
professionalThomas Stockwell6-Apr-08 3:43 
GeneralRe: Automatic Properties on .NET 2.0 Pin
Ed.Poore28-Mar-08 10:20
Ed.Poore28-Mar-08 10:20 
GeneralPrompt for Report Paramters Pin
Miszou27-Mar-08 8:59
Miszou27-Mar-08 8:59 
GeneralSerialPort Pin
amirreza_nl27-Mar-08 5:37
amirreza_nl27-Mar-08 5:37 
GeneralRe: SerialPort Pin
Alan N27-Mar-08 9:23
Alan N27-Mar-08 9:23 
GeneralRe: SerialPort Pin
amirreza_nl27-Mar-08 20:06
amirreza_nl27-Mar-08 20:06 
GeneralRe: SerialPort Pin
Luc Pattyn27-Mar-08 9:38
sitebuilderLuc Pattyn27-Mar-08 9:38 
Generaldisable smartcard pin dialog in CmsSigner and get valid pkcs7 message Pin
krazysmile27-Mar-08 4:37
krazysmile27-Mar-08 4:37 
Hey everyone.

My main goal, is to sign a message with a smartcard, without raising a dialog for the pin.(C#, .NET >= 2.0).

From the example provided in:http://msdn2.microsoft.com/en-us/library/system.security.cryptography.cspparameters.aspx
I have managed to disable pin dialog raise.
With the following code, i dont need to input the pin and all went ok.


// Create a new CspParameters object that identifies a<br />
// Smart Card CryptoGraphic Provider.<br />
CspParameters csp = new CspParameters(1, "Datakey RSA CSP");<br />
csp.Flags = CspProviderFlags.UseDefaultKeyContainer;<br />
<br />
//password do token<br />
System.Security.SecureString pwd = new System.Security.SecureString();<br />
pwd.AppendChar('1'); pwd.AppendChar('2'); pwd.AppendChar('3'); pwd.AppendChar('4');<br />
csp.KeyPassword = pwd;<br />
<br />
csp.KeyNumber = (int)KeyNumber.Signature;<br />
<br />
// Initialize an RSACryptoServiceProvider object using<br />
// the CspParameters object.<br />
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(csp);<br />
<br />
// Create some data to sign.<br />
byte[] data = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 };<br />
<br />
Console.WriteLine("Data         : " + BitConverter.ToString(data));<br />
<br />
// Sign the data using the Smart Card CryptoGraphic Provider.<br />
byte[] sig = rsa.SignData(data, "SHA1");<br />
<br />
Console.WriteLine("Signature    : " + BitConverter.ToString(sig));<br />
<br />
// Verify the data using the Smart Card CryptoGraphic Provider.<br />
bool verified = rsa.VerifyData(data, "SHA1", sig);<br />
<br />
Console.WriteLine("Verified     : " + verified);




Now i want to do the same thing with the example provided in:
http://msdn2.microsoft.com/en-us/library/bb924544.aspx

Meaning, i want to create a CmsSigner passing it the correct CspParameters, in order to sign the pkcs7 message with the smartcard without raising a dialog box for the pin.
something like:


static public byte[] SignMsg2(Byte[] msg, X509Certificate2 signerCert, bool detached)<br />
{<br />
    //  Place message in a ContentInfo object.<br />
    //  This is required to build a SignedCms object.<br />
    ContentInfo contentInfo = new ContentInfo(msg);<br />
<br />
    //  Instantiate SignedCms object with the ContentInfo above.<br />
    //  Has default SubjectIdentifierType IssuerAndSerialNumber.<br />
    SignedCms signedCms = new SignedCms(contentInfo, detached);<br />
<br />
<br />
    CspParameters csp = new CspParameters(1, "Datakey RSA CSP");<br />
    csp.Flags = CspProviderFlags.UseDefaultKeyContainer;<br />
<br />
<br />
    //password do token<br />
    System.Security.SecureString pwd = new System.Security.SecureString();<br />
    pwd.AppendChar('1'); pwd.AppendChar('2'); pwd.AppendChar('3'); pwd.AppendChar('4');<br />
    csp.KeyPassword = pwd;<br />
<br />
    csp.KeyNumber = (int)KeyNumber.Signature;<br />
    csp.Flags = CspProviderFlags.NoPrompt;      //no prompt for the pin!<br />
<br />
    //Formulate a CmsSigner object for the signer.<br />
    CmsSigner cmsSigner = new CmsSigner(csp);<br />
<br />
    // Include the following line if the top certificate in the<br />
    // smartcard is not in the trusted list.<br />
    cmsSigner.IncludeOption = X509IncludeOption.EndCertOnly;<br />
<br />
    //  Sign the CMS/PKCS #7 message. The second argument is<br />
    //  needed to ask for the pin.<br />
    signedCms.ComputeSignature(cmsSigner, false);<br />
<br />
    //  Encode the CMS/PKCS #7 message.<br />
    return signedCms.Encode();<br />
}


This does run, but has 2 major issues:
- it still asks for the pin;
- when i putt the correct pin, the message is signed and encoded (the function runs till the end), but the pkcs7 message that is returned, is wrong: in my example, i use this to sign a pdf, and it says something like: "PKCS/ Parsing error: Incorrect version";



Anyone as any input on this subject?
Really Apreciate.

Regards
GeneralRe: disable smartcard pin dialog in CmsSigner and get valid pkcs7 message Pin
krazysmile3-Apr-08 1:29
krazysmile3-Apr-08 1:29 
GeneralIMAP Select command for selecting Sent Items folder. Pin
Sivasankari Jayaraj27-Mar-08 2:11
Sivasankari Jayaraj27-Mar-08 2:11 
GeneralRe: IMAP Select command for selecting Sent Items folder. Pin
Pete O'Hanlon27-Mar-08 2:29
mvePete O'Hanlon27-Mar-08 2:29 
GeneralRe: IMAP Select command for selecting Sent Items folder. Pin
a123_12327-Mar-08 23:36
a123_12327-Mar-08 23:36 
GeneralRe: IMAP Select command for selecting Sent Items folder. Pin
Pete O'Hanlon28-Mar-08 0:47
mvePete O'Hanlon28-Mar-08 0:47 
GeneralRe: IMAP Select command for selecting Sent Items folder. Pin
a123_12331-Mar-08 18:42
a123_12331-Mar-08 18:42 
QuestionObject Consistency - Part II Pin
Zavullon26-Mar-08 22:46
Zavullon26-Mar-08 22:46 
GeneralRe: Object Consistency - Part II Pin
Pete O'Hanlon27-Mar-08 0:46
mvePete O'Hanlon27-Mar-08 0:46 
GeneralRe: Object Consistency - Part II [modified] Pin
Zavullon27-Mar-08 2:33
Zavullon27-Mar-08 2:33 
GeneralRe: Object Consistency - Part II Pin
Pete O'Hanlon27-Mar-08 3:04
mvePete O'Hanlon27-Mar-08 3:04 
Questiondelay signing Pin
Ahmad Adnan26-Mar-08 3:49
Ahmad Adnan26-Mar-08 3:49 
General[Duplicate Post]Re: delay signing Pin
Scott Dorman26-Mar-08 4:09
professionalScott Dorman26-Mar-08 4:09 
Questiondelay signing Pin
Ahmad Adnan26-Mar-08 3:48
Ahmad Adnan26-Mar-08 3:48 
QuestionHow to shuttle callbacks from a C++ exe to a .NET DLL (or events from dll to exe) Pin
FiddlerMD25-Mar-08 10:53
FiddlerMD25-Mar-08 10:53 
AnswerRe: How to shuttle callbacks from a C++ exe to a .NET DLL (or events from dll to exe) Pin
led mike25-Mar-08 11:04
led mike25-Mar-08 11:04 
General.NET Framework Class Library Pin
JBAK_CP25-Mar-08 10:20
JBAK_CP25-Mar-08 10:20 
GeneralRe: .NET Framework Class Library Pin
led mike25-Mar-08 10:28
led mike25-Mar-08 10:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.