<bdo id='FniKE'></bdo><ul id='FniKE'></ul>
  • <i id='FniKE'><tr id='FniKE'><dt id='FniKE'><q id='FniKE'><span id='FniKE'><b id='FniKE'><form id='FniKE'><ins id='FniKE'></ins><ul id='FniKE'></ul><sub id='FniKE'></sub></form><legend id='FniKE'></legend><bdo id='FniKE'><pre id='FniKE'><center id='FniKE'></center></pre></bdo></b><th id='FniKE'></th></span></q></dt></tr></i><div id='FniKE'><tfoot id='FniKE'></tfoot><dl id='FniKE'><fieldset id='FniKE'></fieldset></dl></div>
      <legend id='FniKE'><style id='FniKE'><dir id='FniKE'><q id='FniKE'></q></dir></style></legend>
    1. <tfoot id='FniKE'></tfoot>

        <small id='FniKE'></small><noframes id='FniKE'>

        TripleDES:指定的密钥是“TripleDES"的已知弱密钥

        时间:2023-06-02

                <tbody id='gCW45'></tbody>
              • <tfoot id='gCW45'></tfoot>
              • <i id='gCW45'><tr id='gCW45'><dt id='gCW45'><q id='gCW45'><span id='gCW45'><b id='gCW45'><form id='gCW45'><ins id='gCW45'></ins><ul id='gCW45'></ul><sub id='gCW45'></sub></form><legend id='gCW45'></legend><bdo id='gCW45'><pre id='gCW45'><center id='gCW45'></center></pre></bdo></b><th id='gCW45'></th></span></q></dt></tr></i><div id='gCW45'><tfoot id='gCW45'></tfoot><dl id='gCW45'><fieldset id='gCW45'></fieldset></dl></div>

                <small id='gCW45'></small><noframes id='gCW45'>

                  <bdo id='gCW45'></bdo><ul id='gCW45'></ul>
                • <legend id='gCW45'><style id='gCW45'><dir id='gCW45'><q id='gCW45'></q></dir></style></legend>
                • 本文介绍了TripleDES:指定的密钥是“TripleDES"的已知弱密钥,不能使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在使用 .NET 3.0 类 System.Security.Cryptography.MACTripleDES 类来生成 MAC 值.不幸的是,我正在使用一个使用1111111111111111"(作为十六进制)作为单长 DES 密钥的硬件设备.System.Security.Cryptography 库会对密钥进行一些完整性检查,如果您尝试使用加密弱密钥,则会返回异常.

                  I'm using the .NET 3.0 class System.Security.Cryptography.MACTripleDES class to generate a MAC value. Unfortunately, I am working with a hardware device that uses "1111111111111111" (as hex) as a single-length DES key. The System.Security.Cryptography library does some sanity checking on the key and returns a Exception if you try to use a cryptographically weak key.

                  例如:

                  byte[] key = new byte[24];
                  for (int i = 0; i < key.Length; i++)
                    key[i] = 0x11;
                  
                  byte[] data = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                  byte[] computedMac = null;
                  using (MACTripleDES mac = new MACTripleDES(key))
                  {
                    computedMac = mac.ComputeHash(data);
                  }
                  

                  抛出异常

                  System.Security.Cryptography.CryptographicException : Specified key is a known weak key for 'TripleDES' and cannot be used.
                  

                  我知道这不是安全密钥.在生产中,设备将使用新的安全密钥进行闪存.同时,有什么方法可以抑制这个异常被抛出?也许是 app.config 或注册表设置?

                  I know this is not a secure key. In production, the device will be flashed with a new, secure key. In the mean time, is there any way to inhibit this Exception from being thrown? Perhaps an app.config or registry setting?

                  由于算法强制奇校验,密钥实际上是 101010....我不确定这是否适用于 DES 算法,或者只是我所做的支付处理工作中的一个要求.

                  The key would actually be 101010... due to the algorithm forcing odd parity. I'm not sure if this is universal to the DES algorithm or just a requirement in the payment processing work I do.

                  编辑 2:Daniel 在下面的回答中有一些关于 .NET 黑客的非常好的信息.不幸的是,我无法使用这种技术解决我的问题,但仍然有一些有趣的阅读.

                  Edit 2: Daniel's answer below has some very good information about hacking .NET. Unfortunately, I wasn't able to solve my problem using this technique, but there is still some interesting reading there.

                  推荐答案

                  您可以在 DESCryptoServiceProvider.

                  <1111111111111111> 不是弱 DES 密钥.

                  <1111111111111111> is not a weak DES key.

                  这将计算一个 DES CBC-MAC:

                  This will calculate a DES CBC-MAC:

                  public static byte[] CalcDesMac(byte[] key, byte[] data){
                          DESCryptoServiceProvider des = new DESCryptoServiceProvider();
                          des.Key = key;
                          des.IV = new byte[8];
                          des.Padding = PaddingMode.Zeros;
                          MemoryStream ms = new MemoryStream();
                          using(CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write)){
                            cs.Write(data, 0, data.Length);
                          }
                          byte[] encryption = ms.ToArray();
                          byte[] mac = new byte[8];
                          Array.Copy(encryption, encryption.Length-8, mac, 0, 8);
                          PrintByteArray(encryption);
                          return mac;
                      }
                  

                  这篇关于TripleDES:指定的密钥是“TripleDES"的已知弱密钥,不能使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:rsacryptoserviceprovider 使用 x509 证书 c# 下一篇:C# 中的非对称加密示例

                  相关文章

                  最新文章

                    • <bdo id='tS12Y'></bdo><ul id='tS12Y'></ul>

                      <i id='tS12Y'><tr id='tS12Y'><dt id='tS12Y'><q id='tS12Y'><span id='tS12Y'><b id='tS12Y'><form id='tS12Y'><ins id='tS12Y'></ins><ul id='tS12Y'></ul><sub id='tS12Y'></sub></form><legend id='tS12Y'></legend><bdo id='tS12Y'><pre id='tS12Y'><center id='tS12Y'></center></pre></bdo></b><th id='tS12Y'></th></span></q></dt></tr></i><div id='tS12Y'><tfoot id='tS12Y'></tfoot><dl id='tS12Y'><fieldset id='tS12Y'></fieldset></dl></div>
                      <legend id='tS12Y'><style id='tS12Y'><dir id='tS12Y'><q id='tS12Y'></q></dir></style></legend>

                      <small id='tS12Y'></small><noframes id='tS12Y'>

                      <tfoot id='tS12Y'></tfoot>