NCryptoki

 

Posts From November, 2011

How to extract a private key object 

Posted by Ugo Chirico Sunday, November 20, 2011 3:58:00 PM Categories: PKCS#11

One of our customers asked an interesting questions:- "Is it possible to export a private key using NCryptoki?"

The answer is yes if, and only if, the private key is extractable (some tokens may not allow to extract a private key).
Below there is a snippet to export a private key:

 // Searchs for an RSA private key object
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));
            
// Launchs the search specifying the template just created
CryptokiCollection objects = session.Objects.Find(template, 1);

if(objects.count == 0)
{
     // PRIVATE KEY NOT FOUND
     return false;
}

// takes the first object as key
RSAPrivateKey privateKey = (RSAPrivateKey)objects[0];

// check if extractable
if(!privateKey.Extractable)
{
    // NOT EXTRACTABLE    
    return false;
}
// Extract modulus and private exponent
byte[] modulus = privateKey.Modulus;
byte[] privateExponent = privateKey.PrivateExponent; 

Gravatar

New release of Virtual Cryptoki 

Posted by Ugo Chirico Monday, November 14, 2011 1:09:00 PM Categories: Virtual Cryptoki

After the new release of Virtual Cryptoki, that fixes several known bugs (that many of you have asked for a long time), we have found a very strange bug in our Virtual Cryptoki. If the smart card service is down the Virtual Cryptoki generates an exception while opening a session.

We have fixed it in the new version 1.0.6.4.

Gravatar

Welcometo NCryptoki Blog 

Posted by Ugo Chirico Monday, November 14, 2011 1:04:00 PM

This is the NCryptoki official blog.

We'll post news, case studies, technical matters, and so on about NCryptoki.

Gravatar
2011 by Ugo Chirico
http://www.ncryptoki.com/Blog/ViewArchive.aspx?month=11&year=2011&pageid=10&mid=26