Read Key value, also if it is sensitive

10/5/2015 4:28:43 PM
Gravatar
Total Posts 33

Read Key value, also if it is sensitive

Can I extract/read the value of a key if it is set as Sensitive?

 

I have this function:

 

        static public <span data-scayt_word="CryptokiCollection" data-scaytid="7">CryptokiCollection <span data-scayt_word="findSecretKey" data-scaytid="9">findSecretKey(Session session, String label, String type)
        {
            <span data-scayt_word="CryptokiCollection" data-scaytid="10">CryptokiCollection <span data-scayt_word="templatePub" data-scaytid="12">templatePub = new <span data-scayt_word="CryptokiCollection" data-scaytid="11">CryptokiCollection();

            if (!label.Equals("") || label != "")
            {
                templatePub.Add(new <span data-scayt_word="ObjectAttribute" data-scaytid="16">ObjectAttribute(ObjectAttribute.CKA_LABEL, label));
            }
            if (type.Equals(Settings.AES))
                templatePub.Add(new <span data-scayt_word="ObjectAttribute" data-scaytid="17">ObjectAttribute(ObjectAttribute.CKA_KEY_TYPE, Key.CKK_AES));
            else if (type.Equals(Settings.DES3))
                templatePub.Add(new <span data-scayt_word="ObjectAttribute" data-scaytid="18">ObjectAttribute(ObjectAttribute.CKA_KEY_TYPE, Key.CKK_DES3));

            templatePub.Add(new <span data-scayt_word="ObjectAttribute" data-scaytid="19">ObjectAttribute(ObjectAttribute.CKA_CLASS, CryptokiObject.CKO_SECRET_KEY));
            <span data-scayt_word="CryptokiObject" data-scaytid="22">CryptokiObject <span data-scayt_word="RootKey" data-scaytid="23">RootKey = session.Objects.Find(<span data-scayt_word="templatePub" data-scaytid="20">templatePub);

            // <span data-scayt_word="Launchs" data-scaytid="1">Launchs the search with the template just created
            <span data-scayt_word="CryptokiCollection" data-scaytid="2">CryptokiCollection objects = session.Objects.Find(<span data-scayt_word="templatePub" data-scaytid="3">templatePub, 10);
            // If the private keys is found continue
            if (objects.Count > 0)
            {
                //Gets the first object found
                <span data-scayt_word="SecretKey" data-scaytid="4">SecretKey key;
                key = (<span data-scayt_word="SecretKey" data-scaytid="5">SecretKey)objects[0];
                Console.WriteLine("Found: " + ((<span data-scayt_word="SecretKey" data-scaytid="6">SecretKey)objects[0]).Label);
                return objects;
            }
            else
                return null;
        }

 

it returns error if the key is sensitive. How can I read the value of this key?

 

I have to export it to import it in another <span data-scayt_word="HSM" data-scaytid="32">HSM.