<link>http://www.ncryptoki.com/forum.aspx</link> <description /> <docs>http://www.rssboard.org/rss-specification</docs> <generator>mojoPortal Forum module</generator> <item> <title>Re: Use Ncryptoki to sign with PFX problem solved successfully, thanks!

 

But I have new Error in line "CryptokiObject priKey = CurrentSession.Objects.Create(template);"  this error is Error n.209

 

Any help please!

]]>
http://www.ncryptoki.com/Forums/Thread.aspx?pageid=9&t=44~-1#post237 Sylpho http://www.ncryptoki.com/Forums/Thread.aspx?pageid= Tue, 10 Jan 2012 17:26:32 GMT Re: Use Ncryptoki to sign with PFX this is issue is not related to NCryptoki. It is related to MS crypto engine.

Check this to see if it solves your problem:

http://www.zomeon.com/949727/bouncycastle-rsaprivatekey-to-net-rsaprivatekey

]]>
http://www.ncryptoki.com/Forums/Thread.aspx?pageid=9&t=44~-1#post235 Sylpho http://www.ncryptoki.com/Forums/Thread.aspx?pageid= Mon, 09 Jan 2012 10:38:41 GMT
Re: Use Ncryptoki to sign with PFX I use this code for extract Private Key of .pfx file.

private bool importKeyPair(X509Certificate2 cert, string id, string label, bool priv, bool modifiable)
{
if (!cert.HasPrivateKey)
{
showError("Certificate doesn't have private key. Import failed!");
return false;
}

AsymmetricAlgorithm keyPair = cert.PrivateKey;

if (keyPair is RSA)
{
RSAParameters keyParams = ((RSA)keyPair).ExportParameters(true);
CryptokiCollection template = new CryptokiCollection();
template.Add(new ObjectAttribute(ObjectAttribute.CKA_CLASS, CryptokiObject.CKO_PRIVATE_KEY));
template.Add(new ObjectAttribute(ObjectAttribute.CKA_KEY_TYPE, Key.CKK_RSA));
template.Add(new ObjectAttribute(ObjectAttribute.CKA_SUBJECT, cert.SubjectName.RawData));
template.Add(new ObjectAttribute(ObjectAttribute.CKA_ID, id));
template.Add(new ObjectAttribute(ObjectAttribute.CKA_LABEL, label));
template.Add(new ObjectAttribute(ObjectAttribute.CKA_TOKEN, true));
template.Add(new ObjectAttribute(ObjectAttribute.CKA_MODULUS, keyParams.Modulus));
template.Add(new ObjectAttribute(ObjectAttribute.CKA_PUBLIC_EXPONENT, keyParams.Exponent));
template.Add(new ObjectAttribute(ObjectAttribute.CKA_PRIVATE_EXPONENT, keyParams.D));
template.Add(new ObjectAttribute(ObjectAttribute.CKA_PRIVATE, priv));
template.Add(new ObjectAttribute(ObjectAttribute.CKA_MODIFIABLE, modifiable));
CryptokiObject priKey = CurrentSession.Objects.Create(template);
}

return true;

}

 

But i have error in line  " RSAParameters keyParams = ((RSA)keyPair).ExportParameters(true);"

this error is "Key not valid for use in specified state."

an answer to this issue??

]]>
http://www.ncryptoki.com/Forums/Thread.aspx?pageid=9&t=44~-1#post234 Sylpho http://www.ncryptoki.com/Forums/Thread.aspx?pageid= Wed, 04 Jan 2012 16:53:40 GMT
Re: Use Ncryptoki to sign with PFX You can find an example on how to sign a text using the private key in C# example in the SDK.

Once you have imported a pfx you can sign by this snippet :

 // prepares for the signature
string helloworld = "Hello World";
byte[] text = Encoding.ASCII.GetBytes(helloworld);
               
// launches the digital signature operation with a RSA_PKCS mechanism
nRes = session.SignInit(Mechanism.SHA1_RSA_PKCS, privateKey);

// computes the signature
byte[] signature = session.Sign(text);

// launches the digital signature verification with a RSA_PKCS mechanism                
nRes = session.VerifyInit(Mechanism.SHA1_RSA_PKCS, publicKey);

// verifies the signature
nRes = session.Verify(text, signature);

// results if nRes == 0 means that the verification is OK
Console.Write("Verified " + (nRes == 0)); 
]]>
http://www.ncryptoki.com/Forums/Thread.aspx?pageid=9&t=44~-1#post233 Sylpho http://www.ncryptoki.com/Forums/Thread.aspx?pageid= Wed, 04 Jan 2012 08:07:59 GMT
Re: Use Ncryptoki to sign with PFX an answer to this issue is urgent!

]]>
http://www.ncryptoki.com/Forums/Thread.aspx?pageid=9&t=44~-1#post232 Sylpho http://www.ncryptoki.com/Forums/Thread.aspx?pageid= Tue, 03 Jan 2012 18:59:44 GMT
Use Ncryptoki to sign with PFX I havent found an example that shows me how to use the Ncryptoki Wrapper to sign with PFX, can you provide me one or send how can i find it?, as i have read the information of this link: http://wiki.ncryptoki.com/How-to-import-a-pfx-or-a-p12-file.ashx shows how to import it but how i use it in the method Sign?

]]>
http://www.ncryptoki.com/Forums/Thread.aspx?pageid=9&t=44~-1#post229 Sylpho http://www.ncryptoki.com/Forums/Thread.aspx?pageid= Wed, 14 Dec 2011 23:43:32 GMT