如何在 iPhone 上生成 openssl 3des 解密的密钥时间表

发布于 2024-10-16 17:13:56 字数 1056 浏览 1 评论 0原文

我需要解密一些在运行 mono (C#) 的系统上进行 3des 编码的数据,

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

我找到了一个如下所示的示例,当我安装了 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 专业知识的人,使用该库是该项目的先决条件)

I need to decrypt some data that has been 3des encoded on system running mono (C#)

I need to use openssl and decrypt on the iPhone.

I found an example which looks like this, and it runs without error on the iphone when I have openssl etc installed, but generates the wrong result for my test case which I've verified on the encoding system. The initialisation vector is correct, but what should I set the key schedule to since the only information I have is the input?

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

The decoding on the mono system is done with the following code;

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

As far as I can tell, the key schedule isn't being specified, so I don't know what to set it to? I guess it gets derived from the key ... penny starting to drop ... but how?

Any ideas? (ideally from people with openssl expertise, use of this library is a pre-requisite for the project)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春庭雪 2024-10-23 17:13:56

DES_cblock 的 typedef 开始:

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

Starting with the typedef for a DES_cblock:

typedef unsigned char DES_cblock[8];

Fill in you own code for the comments and use something like:

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文