Hello to all!
I have a few newbie questions :)
I'm trying to encrypt using a 3des/2des key but I haven't a good result.
In vb6 I don't get any error, I found the Key inside my HSM and I try to encrypt using it but "encrypted" doesn't return anything:
This is part of my code under VB6:
Set objs = sess.Objects
Dim template As New CryptokiCollection
Dim att As ObjectAttribute
Set att = New ObjectAttribute
att.Set CKA_LABEL, "CPVISA"
Dim attrList As CryptokiCollection
Set attrList = New CryptokiCollection
attrList.Add att
Dim objList As CryptokiCollection
Set objList = objs.Find(attrList, 4)
MsgBox ("Found : " & objList.count)
Dim u
For u = 0 To objList.count - 1
MsgBox ("Found : " & objList.Item(u))
Next u
Set mech = New Mechanism
' prepare buffer to encrypt
Dim toEncrypt(16) As Byte
Dim encrypted() As Byte
For i = 0 To 15
If i < 7 Then
toEncrypt(i) = &H41
Else
toEncrypt(i) = &H42
End If
Next
mech.Set CKM_DES3_ECB, Nothing
sess.EncryptInit(mech, objList.Item(0))
encrypted = sess.Encrypt(toEncrypt(0))
I guess I'm doing something wrong....
I tried to do the same under C#, using the wiki example code:
http://wiki.ncryptoki.com/Encrypt-and-Decrypt-with-a-DES3-key.ashx
But I get a error in this line:
session.EncryptInit(Mechanism.CKM_DES3_ECB);
It Could be that session.EncryptInit() take two parameters? Mech & Key?
Anybody can share a working example code?
Thanks !!
Best Regards,