locked
crypto RRS feed

  • Question

  • hello guys i have a encryption and decryption  code

    in project settings i have a stored encrypted data for myslq connection but when i try to decrypt the string it says "BAD DATA"

    here is my sample code

    private void Decryption(string Encrypted) {

                byte[] ecrypted = Convert.FromBase64String(Encrypted);
                MemoryStream ms = new MemoryStream();
                CryptoStream decrypt = new CryptoStream(ms, tripledes.CreateDecryptor(),CryptoStreamMode.Write);
                decrypt.Write(ecrypted, 0 ,ecrypted.Length);
                decrypt.FlushFinalBlock();
                MessageBox.Show(Encoding.Unicode.GetString(ms.ToArray()));

            }

    Sunday, June 10, 2012 12:53 PM

Answers

  • Hi, 

    I guess error is because of, you  passing empty MemoryStream to CryptoStream, change the code to, 

      byte[] ecrypted = Convert.FromBase64String(Encrypted);
      MemoryStream ms = new MemoryStream(encrypted);
      CryptoStream decrypt = new CryptoStream(ms, tripledes.CreateDecryptor(),CryptoStreamMode.Write);
      decrypt.Write(ecrypted, 0 ,ecrypted.Length);
      decrypt.FlushFinalBlock();
      MessageBox.Show(Encoding.Unicode.GetString(ms.ToArray()));

    Hope this helps you...


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".


    • Edited by Kris444 Sunday, June 10, 2012 2:42 PM
    • Proposed as answer by Alexander Sun Monday, June 11, 2012 8:25 AM
    • Marked as answer by Alexander Sun Tuesday, June 26, 2012 9:20 AM
    Sunday, June 10, 2012 2:42 PM

All replies

  • hi,

    I would go for MD5 cryprograpgy. Check here: http://tutorialgenius.blogspot.com/2010/03/c-md5-encryption-and-decryption.html


    Mitja

    Sunday, June 10, 2012 1:00 PM
  • Hi, 

    I guess error is because of, you  passing empty MemoryStream to CryptoStream, change the code to, 

      byte[] ecrypted = Convert.FromBase64String(Encrypted);
      MemoryStream ms = new MemoryStream(encrypted);
      CryptoStream decrypt = new CryptoStream(ms, tripledes.CreateDecryptor(),CryptoStreamMode.Write);
      decrypt.Write(ecrypted, 0 ,ecrypted.Length);
      decrypt.FlushFinalBlock();
      MessageBox.Show(Encoding.Unicode.GetString(ms.ToArray()));

    Hope this helps you...


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".


    • Edited by Kris444 Sunday, June 10, 2012 2:42 PM
    • Proposed as answer by Alexander Sun Monday, June 11, 2012 8:25 AM
    • Marked as answer by Alexander Sun Tuesday, June 26, 2012 9:20 AM
    Sunday, June 10, 2012 2:42 PM
  • yup ithink the problem is empty memorystream because im only accessing an encrypted string on properties-settings of my project solution
    Sunday, June 10, 2012 3:13 PM