Welcome
Guest
, you are in:
<root>
•
Login
NCryptoki Wiki
Navigation
¶
Main Page
Random Page
Create a new Page
All Pages
Categories
Navigation Paths
Administration
File Management
Create Account
Search the wiki
»
Back
How to extract an X509Certificate
Modified on 2012/02/02 16:12
by
Administrator
Categorized as
CSharp
X509Certificates can be extracted from the token if they are marked as extractable. This is a snippet to extract a certificate and convert it to X509Certificate2 class: @@// Searchs for an X509Certificate object CryptokiCollection template = new CryptokiCollection(); template.Add(new ObjectAttribute(ObjectAttribute.CKA_CLASS, CryptokiObject.CKO_CERTIFICATE)); template.Add(new ObjectAttribute(ObjectAttribute.CKA_CERTIFICATE_TYPE, Certificate.CKC_X_509)); // Launches the search specifying the template just created CryptokiCollection objects = session.Objects.Find(template, 1); if(objects.count == 0) { // CERTIFICATE NOT FOUND return false; } // takes the first object as key X509Certificate certificate = (X509Certificate)objects[0]; // convert to X509Certificate2 X509Certificate2 cert = Utils.ConvertCertificate(certificate) @@
Meta Keywords:
Meta Description:
Change Comment:
ScrewTurn Wiki
version 3.0.4.560. Some of the icons created by
FamFamFam
.