Welcome Guest, you are in: Login

NCryptoki Wiki

RSS RSS

Navigation





Search the wiki
»

Cryptware
PoweredBy

List all keys, Public and Private

RSS
Modified on 2017/07/20 12:46 by Administrator Categorized as Uncategorized
This snippet shows how to list all public and private keys:

// Searchs for private key objects
CryptokiCollection templatePri = new CryptokiCollection();
templatePri .Add(new ObjectAttribute(ObjectAttribute.CKA_CLASS, CryptokiObject.CKO_PRIVATE_KEY));
            
// Launches the search specifying the template just created
CryptokiCollection priKeyObjects = session.Objects.Find(templatePri , 100);

// prints the label of all keys for(int i = 0; i < priKeyObjects .count(); i++) { RSAPrivateKey privateKey = (RSAPrivateKey)priKeyObjects i; Console.WriteLine("Private Key: " + privateKey.Label); }

// Searchs for public key objects CryptokiCollection templatePub = new CryptokiCollection(); templatePub .Add(new ObjectAttribute(ObjectAttribute.CKA_CLASS, CryptokiObject.CKO_PUBLIC_KEY)); // Launches the search specifying the template just created CryptokiCollection pubKeyObjects = session.Objects.Find(templatePub , 100);

// prints the label of all keys for(int i = 0; i < pubKeyObjects .count(); i++) { RSAPublicKey publicKey = (RSAPublicKey )pubKeyObjectsi; Console.WriteLine("Public Key: " + publicKey.Label); }

ScrewTurn Wiki version 3.0.4.560. Some of the icons created by FamFamFam.