<link>http://ncryptoki.com/forum.aspx</link> <description /> <docs>http://www.rssboard.org/rss-specification</docs> <generator>mojoPortal Forum module</generator> <item> <title>Re: upload private key to token return error n:5 Hi,

error n.5 is CKR_GENERAL_ERROR.

It is raised by the underlying PKCS#11 module and usually it means that the  token is in some invalid state such as not formatted or finished or something else.

You should refer to its documentations to know what cause that problem.

]]>
http://ncryptoki.com/Forums/Thread.aspx?pageid=9&t=89~-1#post426 r0otsharp http://ncryptoki.com/Forums/Thread.aspx?pageid= Tue, 22 Jan 2013 13:26:27 GMT upload private key to token return error n:5 hello

 

i want to upload private key from p12 file to token but get error n:5. I'm using bellow code:

X509Certificate2 cert = new X509Certificate2("c.pfx", "1234", X509KeyStorageFlags.Exportable);
if (!cert.HasPrivateKey)
{

}
AsymmetricAlgorithm privateKey = cert.PrivateKey;
string NameLabel = cert.GetNameInfo(X509NameType.SimpleName, false);
CryptokiCollection attList = new CryptokiCollection();
RSAParameters parameters1 = new RSAParameters();
if (privateKey is RSA)
{
PrivateKeyInfo privateKeyInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(pair.Private);
byte[] serializedKey = privateKeyInfo.ToAsn1Object().GetDerEncoded();
RsaPrivateCrtKeyParameters keyParams = (RsaPrivateCrtKeyParameters)pair.Private;
//Private Key
parameters1 = ((RSA)cert.PrivateKey).ExportParameters(true);
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_CLASS, 0x03));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_KEY_TYPE, 0x00));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_PRIVATE, true));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_SUBJECT, cert.SubjectName.RawData));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_ID, "10"));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_LABEL, NameLabel));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_TOKEN, true));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_MODULUS, parameters1.Modulus));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_PUBLIC_EXPONENT, parameters1.Exponent ));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_PRIVATE_EXPONENT, parameters1.D));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_KEY_TYPE, Key.CKK_RSA));
// attList.Add(new ObjectAttribute(ObjectAttribute.CKH_CLOCK, true));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_MODIFIABLE, true));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_LOCAL, true));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_EXTRACTABLE, false));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_NEVER_EXTRACTABLE, true));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_SENSITIVE, true));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_ALWAYS_SENSITIVE, true));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_DERIVE, false));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_LOCAL, false));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_DECRYPT, true));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_SIGN, true));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_SIGN_RECOVER, false));
attList.Add(new ObjectAttribute(ObjectAttribute.CKA_UNWRAP, false));

session.Objects.Create(attList);
}

 

can you tell me what's wrong this code???

 

Best Regards

]]>
http://ncryptoki.com/Forums/Thread.aspx?pageid=9&t=89~-1#post425 r0otsharp http://ncryptoki.com/Forums/Thread.aspx?pageid= Tue, 22 Jan 2013 10:47:58 GMT