Click here to Skip to main content
13,043,898 members (47,762 online)
Rate this:
Please Sign up or sign in to vote.
Hi all,
I am using aladin etoken for encryption.
I have stored DES key in etoken.
My code is running nicely when i m giving plain text with 40 characters.
It encrypt and decrypt perfectly.
but when i m giving characters more or less than is failing for me
I m using PKCS11 code. Dot net dll comes with aladin sdk only.
my code is as below.

 public void encryptDES(byte[] src)
                PKCS11.Object[] hkey = new PKCS11.Object[0];
                PKCS11.Slot[] sl = new PKCS11.Slot[0];
                sl = PKCS11.GetSlotList(false);
                PKCS11.Slot sl1 = new PKCS11.Slot();
                sl1 = sl[0];
                sc = PKCS11.OpenSession(sl1, 6);
                int a = sc.Login(1, "Inspira@123");
                Console.WriteLine("Sucessfully Logged In");
                PKCS11.Mechanism[] mh1 = new PKCS11.Mechanism[500];
                mh1 = PKCS11.GetMechanismList(sl1);
                PKCS11.Mechanism mch2 = new PKCS11.Mechanism();

                byte[] IV = { 12, 13, 14, 15, 16, 17, 18, 19 };
       = 289;
                mch2.iv = IV;
                mch2.length = IV.Length;
                PKCS11.Attribute[] pDESTemplate = new PKCS11.Attribute[2];
                pDESTemplate[0] = new PKCS11.Attribute(PKCS11.CKA_KEY_TYPE, 19);
                pDESTemplate[1] = new PKCS11.Attribute(PKCS11.CKA_CLASS, 4);
                hkey = sc.FindObjects(pDESTemplate);
                PKCS11.Object bj = new PKCS11.Object();
                bj = hkey[0];

                byte[] enct = sc.Encrypt(mch2, bj, src);
                File.WriteAllBytes("D:\\Encrypted.txt", enct);
                Console.WriteLine("Encryped text :" + ASCIIEncoding.ASCII.GetString(enct));
              //  sc.Close();
            catch (Exception ex)
                Console.WriteLine("Error:" + ex.Message + ex.InnerException);

if anyone has any idea about this please help me..
It happens with tripledes also.
and also i m not able to find error code list for pkcs 11 standard by which i can come to know what is actually the error is.

Thanks in advance,
God bless u all .:)
Posted 29-May-13 21:13pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

DES is a block level cipher. You must use a padding mechanish such as CBC,CFB8, OFB8 or PKCS5 etc.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 2 Jun 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100