Error n. 126

6/23/2013 4:00:29 PM
Gravatar
Total Posts 6

Error n. 126

Hi there,

 

I am in process of developing a KMS solution, i have come across NCryptoki in website and have downloaded trial version and now getting hands on with sample code, (TestNCryptoKiVBNet) and getting the error "CryptokiException unhandled" error no 126, what could be the problem

 

 

Regards

D.Paul

6/24/2013 7:50:25 AM
Gravatar
Total Posts 6

Re: Error n. 126

Hi there,

 

I managed to move from the error and now i have created a small sample application to connect to the safnet software HSM,

How to read all the objects which already exist in the HSM to be displayed to a logged in SO or User.

 

My intention is to do the following activites using NCryptoki.dll's .

1. Create and manage new slots.

2. Generate the Issuer keys.
3. Use the Issuer public key (Issuer_PK) to generate the certificate request.
4. Generate or import the following Issuer application keys
5. Generate Random keys
6. Import the CA and Issuer Certificates
7. Wrap / Unwrap keys.
8. Export / Import keys
 

Do you have any relative materials regarding this.

 

thanks

regards

D.Paul

6/26/2013 9:57:47 PM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

Re: Error n. 126

You can refer to our wiki for tutorials, samples and more:

http://wiki.ncryptoki.com

6/27/2013 9:41:06 AM
Gravatar
Total Posts 6

Re: Error n. 126

Hi Mr.Ugo,

 

Thanks for your consideration and reply.

 

I am going through what you have recommended and having some base code on that.

 

As part of it. i am trying to develop random keys just to simulate the functionality of "Generate Key Components",I am using "Safenet, Inc.  Software Only 2.10" as software HSM module.

Below is the code i am using to generate key components.

 

Private Sub cmdGenerateKey_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGenerateKey.Click
Try
txtKey.Text = ""
Dim template As New CryptokiCollection()
Dim objectsAlreadyExist As CryptokiCollection
' ATTRIBUTES FOR A TEMP KEY TO STORE RANDOM KEY GENERATED FROM SOFT HSM.
template.Add(New ObjectAttribute(ObjectAttribute.CKA_CLASS, CryptokiObject.CKO_SECRET_KEY))
template.Add(New ObjectAttribute(ObjectAttribute.CKA_LABEL, "TempKey"))
template.Add(New ObjectAttribute(ObjectAttribute.CKA_TOKEN, False))
template.Add(New ObjectAttribute(ObjectAttribute.CKA_PRIVATE, True))
Select Case Trim(UCase(cboKeyLength.Items(cboKeyLength.SelectedIndex).ToString()))
Case "SINGLE"
template.Add(New ObjectAttribute(ObjectAttribute.CKA_VALUE, session.GenerateRandom(8)))
Case "DOUBLE"
template.Add(New ObjectAttribute(ObjectAttribute.CKA_VALUE, session.GenerateRandom(16)))
Case "TRIPLE"
template.Add(New ObjectAttribute(ObjectAttribute.CKA_VALUE, session.GenerateRandom(24)))
End Select
session.GenerateKey(Mechanism.DES3_KEY_GEN, template)
template.Clear()

template.Add(New ObjectAttribute(ObjectAttribute.CKA_CLASS, CryptokiObject.CKO_SECRET_KEY))
template.Add(New ObjectAttribute(ObjectAttribute.CKA_LABEL, "TempKey"))
objectsAlreadyExist = session.Objects.Find(template, 1)
template.Clear()
Dim keyValue() As Byte
If (objectsAlreadyExist.Count > 0) Then
'TO CHECK IF THE TEMP CREATED DOES EXIST
For Each obj As [Object] In objectsAlreadyExist
Dim secretKey As SecretKey
secretKey = DirectCast(obj, SecretKey)
keyValue = secretKey.KeyValue
Dim shex As String = BitConverter.ToString(keyValue).Replace("-", "")
txtKey.Text = shex
Next
End If
session.Objects.Destroy(obj)
Catch ex As Exception

End Try
End Sub

 

The problem i am facing here

1. what ever may be the length i am choosing (Single or double or triple) i am getting the same length keys (A229E68AD9E543A45D07291A0B73E5EA2FBCDA924FC4346D)

 

how to fix and what i am doing wrong
 

7/8/2013 4:52:14 PM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

Re: Error n. 126

Hi,

the mechanism you used to generate the key is:

Mechanism.DES3_KEY_GEN

It has a fixed key length and generate a new DES3 key with fixed length ignoring what you set in the VALUE field, i.e. the HSM doesn't use the VALUE field to generate the key.

 

7/10/2013 9:40:56 AM
Gravatar
Total Posts 6

How to derive key using clear components

Hi there,

 

I am generating three clear components.

//COMPONENT -1
txtKey1.Text = BitConverter.ToString(OBJSession.GenerateRandom(8)).Replace("-", "");
//COMPONENT -2
txtKey2.Text = BitConverter.ToString(OBJSession.GenerateRandom(8)).Replace("-", "");
//COMPONENT -3
txtKey3.Text = BitConverter.ToString(OBJSession.GenerateRandom(8)).Replace("-", "");

 

and now want to combine the three components to a single key to be stored what should i do.

can you provide some code snippets for this.

 

Thanks

Regards

D.Paul

8/15/2013 2:22:03 PM
Gravatar
Total Posts 7

Re: Error n. 126

Hi Paul,

How did you overcome error n. 126? What does it mean?

 

Thanks