DES加密仅将40个字符数据作为纯文本 [英] DES encryption takes only 40 character data as a plain text

查看:100
本文介绍了DES加密仅将40个字符数据作为纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用aladin etoken进行加密。

我已将DES密钥存储在etoken中。

我的代码正在运行当我给出40个字符的纯文本时很好。

它完全加密和解密。

但是当我给出的字符大于或小于40.时,对我来说是失败的/>
我使用PKCS11代码。 Dot net dll仅附带aladin sdk。

我的代码如下。





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);
           }
       }







如果有人有任何想法关于这个请帮助我..

它也发生在三重奏中。

我也无法找到pkcs 11标准的错误代码列表,我可以通过它来了解实际上错误是什么。



提前谢谢,

上帝保佑你们所有人。:)




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 .:)

推荐答案

DES是块级密码。您必须使用填充机制,如CBC,CFB8,OFB8或PKCS5等。
DES is a block level cipher. You must use a padding mechanish such as CBC,CFB8, OFB8 or PKCS5 etc.


这篇关于DES加密仅将40个字符数据作为纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆