如果我有 IV、加密数据和结果值,我能找到 Triple DES 加密算法中的密钥吗?
这并不意味着任何类型的黑客攻击,我只是尝试在 .NET 中使用 Triple DES 加密技术。我身上有一些测试数据。我必须用给定的数据得到结果。我也有结果了。但价值永远不会匹配。我确信代码没问题(将在下面给出)。所以我认为唯一的可能性可能是密钥错误,所以让我们找到密钥并看看是否匹配。下面是我的代码:
byte[] key = StringToByteArray("5b70649d4ae0bf2af891c167514aa7515b70649d4ae0bf2a");
byte[] iv = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 };
byte[] bytes = Encoding.ASCII.GetBytes("95e4d77c6d6c6c993333303533303833");
TripleDESCryptoServiceProvider tripleDes = new TripleDESCryptoServiceProvider();
tripleDes.Mode = CipherMode.CBC;
//tripleDes.Padding = PaddingMode.None;
tripleDes.Key = key;
tripleDes.IV = iv;
MemoryStream ms = new MemoryStream();
ICryptoTransform encryptor = tripleDes.CreateEncryptor();
CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write);
cs.Write(bytes, 0, bytes.Length);
cs.FlushFinalBlock();
byte[] cipher = ms.ToArray();
string finalValue = ByteToString(cipher, 16); //ByteToString method will convert byte array to string.
最终结果是1B529558534F43D15556AD65C7E396D5674EE8A09E0A29A84389020EF820AC51B7D5E1B33BDA18A2
。 由于我只需要 16 个字节,因此我仅将前 16 个字节转换为十六进制 1B529558534F43D15556AD65C7E396D5
。
但预期结果是76db821f5c7af12dc8d70a6a79cfcb77
如果我能找到密钥,我可能知道密钥中也需要进行某种处理。
感谢您的帮助!
This is not meant for any kind of hacking, I am just trying my hands on Triple DES encryption technique in .NET. I have some test data with me. I have to get the result with the given data. I do also have the result. But the value never matches. I am sure the code is fine (will give that below). So I thought the only possibility could be the key is wrong and so lets find the key and see if that matches. Below is my code:
byte[] key = StringToByteArray("5b70649d4ae0bf2af891c167514aa7515b70649d4ae0bf2a");
byte[] iv = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 };
byte[] bytes = Encoding.ASCII.GetBytes("95e4d77c6d6c6c993333303533303833");
TripleDESCryptoServiceProvider tripleDes = new TripleDESCryptoServiceProvider();
tripleDes.Mode = CipherMode.CBC;
//tripleDes.Padding = PaddingMode.None;
tripleDes.Key = key;
tripleDes.IV = iv;
MemoryStream ms = new MemoryStream();
ICryptoTransform encryptor = tripleDes.CreateEncryptor();
CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write);
cs.Write(bytes, 0, bytes.Length);
cs.FlushFinalBlock();
byte[] cipher = ms.ToArray();
string finalValue = ByteToString(cipher, 16); //ByteToString method will convert byte array to string.
The final result is 1B529558534F43D15556AD65C7E396D5674EE8A09E0A29A84389020EF820AC51B7D5E1B33BDA18A2
.
Since I need only 16 bytes I have converted only first 16 bytes to hex 1B529558534F43D15556AD65C7E396D5
.
But the expected result is 76db821f5c7af12dc8d70a6a79cfcb77
If I can find the key, I may know that there needs to be some kind of processing required in the key as well.
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然这当然是可能的,但我不认为 TripleDESCryptoServiceProvider 类被设计为“反向”工作,以便在您拥有密码、IV 和未加密数据时为您提供密钥。为什么应该这样?
While its certainly possible, I don't think the TripleDESCryptoServiceProvider class is designed to work in "reverse" to give you a key when you have the cypher, IV and the unencrypted data. Why should it?