0

我需要解密一些在运行单声道(C#)的系统上经过 3des 编码的数据

我需要在 iPhone 上使用 openssl 和解密。

我找到了一个看起来像这样的示例,当我安装了 openssl 等时,它在 iphone 上运行没有错误,但是为我在编码系统上验证的测试用例生成了错误的结果。初始化向量是正确的,但是我应该将密钥计划设置为什么,因为我拥有的唯一信息是输入?

   DES_cblock ivec[] = {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};   
   DES_key_schedule  ks1, ks2, ks3; 

   // What (and how) should I set ks1/2/3 to?

   DES_ede3_cbc_encrypt(input,output, 24*8, &ks1, &ks2, &ks3,ivec, DES_DECRYPT);

单声道系统的解码使用以​​下代码完成;

   TripleDESCryptoServiceProvider m_des = new TripleDESCryptoServiceProvider();

   byte[] IV ={0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
   m_des.KeySize = 24*8;

   MemoryStream memStream = new MemoryStream();
   CryptoStream cryptStream = new CryptoStream(memStream,m_des.CreateDecryptor(key, IV), CryptoStreamMode.Write);

   cryptStream.Write(input, 0, input.Length);
   cryptStream.FlushFinalBlock();

据我所知,没有指定关键时间表,所以我不知道将其设置为什么?我猜它是从钥匙中衍生出来的……一分钱开始下降……但是如何呢?

有任何想法吗?(最好来自具有 openssl 专业知识的人,使用这个库是项目的先决条件)

4

1 回答 1

0

从 a 的 typedef 开始DES_cblock

typedef unsigned char DES_cblock[8];

填写您自己的注释代码并使用以下内容:

DES_key_schedule ks1, ks2, ks3;
DES_cblock key_8bytes;

/* ... copy the first 64 bits of the 192 bits into key_8bytes....*/
DES_set_key_unchecked(&key_8bytes, &ks1);

/* ... copy the second 64 bits of the 192 bits into key_8bytes....*/
DES_set_key_unchecked(&key_8bytes, &ks2);

/* ... copy the final 64 bits of the 192 bits into key_8bytes....*/
DES_set_key_unchecked(&key_8bytes, &ks3);
于 2011-02-10T00:40:52.493 回答