title: Encrypt text using Security.Cryptography on ironpython
body: <p>I am trying to make encryption work on sharpdevelop using IronPython to encrypt text but I am getting the error below:</p>
  
  <p>"Specified key is not a valid size for this algorithm."</p>
  
  <p>I tried using all three encodings, tried different size for the key like 128, 256, 1024 and nothing.</p>
  
  <p>This is the code I am using:</p>
  
  <pre><code>import System.Security.Cryptography
  from System.Text import UTF8Encoding, ASCIIEncoding, UnicodeEncoding
  
  self.MD5 = System.Security.Cryptography.MD5CryptoServiceProvider()
  self.DES = System.Security.Cryptography.DESCryptoServiceProvider()
  self.UTF8Encode = UTF8Encoding()
  self.ASCIIEncode = ASCIIEncoding()
  self.Unicode = UnicodeEncoding()
  
  def MD5Hash(self, value):
      return self.MD5.ComputeHash(self.Unicode.GetBytes(value))
  
  def Encrypt(self, StringInput, Key):
      self.DES.Key = self.MD5Hash(Key)
      DES.Mode = CipherMode.ECB()
      buffer = self.UTF8Encode.GetBytes(StringInput)
      return System.Convert.ToBase64String(self.DES.CreateEncryptor().TransformFinalBlock(buffer, 0, len(buffer)))
  
  def Button1Click(self, sender, e):
      self._textBox2.Text = self.Encrypt(self._textBox1.Text, 'keys')
  </code></pre>