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];
byte[] enct = sc.Encrypt(mch2, bj, src);
File.WriteAllBytes("D:\\Encrypted.txt", enct);
Console.WriteLine("Encryped text :" + ASCIIEncoding.ASCII.GetString(enct));
Console.ReadLine();
}
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 .:)