Click here to Skip to main content
Rate this: bad
good
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 40.it 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)
        {
            try
            {
                PKCS11.Object[] hkey = new PKCS11.Object[0];
                PKCS11.Initialize("etpkcs11.dll");
 
                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 };
                mch2.id = 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];
 

                //Encrypt
                byte[] enct = sc.Encrypt(mch2, bj, src);
                File.WriteAllBytes("D:\\Encrypted.txt", enct);
                Console.WriteLine("Encryped text :" + ASCIIEncoding.ASCII.GetString(enct));
 
                Console.ReadLine();
              //  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 .Smile | :)
Posted 29-May-13 22:13pm
MAU7871.6K

1 solution

Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 390
1 Jochen Arndt 165
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 2 Jun 2013
Copyright © CodeProject, 1999-2014
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