3des key Encryption problem VB6 & C#

4/5/2013 2:34:10 PM
Gravatar
Total Posts 5

3des key Encryption problem VB6 & C#

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,

 

 

 

4/7/2013 12:25:06 AM
Gravatar
Total Posts 5

Re: 3des key Encryption problem VB6 & C#

I don't want to seem like I'm bugging you, but anybody can help me with this?   Ugo? Can you help me?

I run the vb6 example code that is located inside the examples folder, without any modification and I have the same problem (It seems that sess.Encrypt(toEncrypt(0)) doesn't return anything).

Sorry again for my questions.

Best Regards!