title: TripleDES: Specified key is a known weak key for 'TripleDES' and cannot be used
body: <p>I'm using the .NET 3.0 class <code>System.Security.Cryptography.MACTripleDES</code> class to generate a MAC value.  Unfortunately, I am working with a hardware device that uses "<code>1111111111111111</code>" (as hex) as a single-length DES key.  The <code>System.Security.Cryptography</code> library does some sanity checking on the key and returns a Exception if you try to use a cryptographically weak key.</p>
  
  <p>For example:</p>
  
  <pre><code>byte[] key = new byte[24];
  for (int i = 0; i &lt; 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);
  }
  </code></pre>
  
  <p>throws an exception</p>
  
  <pre><code>System.Security.Cryptography.CryptographicException : Specified key is a known weak key for 'TripleDES' and cannot be used.
  </code></pre>
  
  <p>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 <code>app.config</code> or registry setting?</p>
  
  <p>Edit:  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.</p>
  
  <p>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.</p>