none
Encryption using TripleDES algorithm RRS feed

  • Question

  • I need to encrypt the file using a password. I am using TripleDES algorithm to do so but while decrypting i get the Error -"The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters." ??
    • Edited by Resh90 Thursday, November 1, 2012 5:40 AM
    • Moved by Lisa Zhu Friday, November 2, 2012 7:31 AM CLR related (From:Visual C# Language)
    Wednesday, October 31, 2012 5:46 PM

All replies

  • This probably means that your implementation is incorrect. Show some details about how you create and decrypt the file.

    Thursday, November 1, 2012 8:10 AM
  • Hi Resh90,

    From your description , I ‘d like to move this post to  the most related forum for better support.

    Thanks for your understanding .

    BTW, please give some more details for us to help on this topic, thanks.

    Regards ,


    Lisa Zhu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, November 2, 2012 7:30 AM
  • This is the code i am using for encryption n decryption-

    class EncryptDecrypt   {

            public static TripleDES CreateDes(string key)
            {
                MD5 md5 = new MD5CryptoServiceProvider();
                TripleDES des = new TripleDESCryptoServiceProvider();
                des.Key = md5.ComputeHash(Encoding.Unicode.GetBytes(key));
                des.IV = new byte[des.BlockSize / 8];
                return des;
            }
          public  byte[] Encryption(string PlainText, string key)
            {
                TripleDES des = CreateDes(key);
                ICryptoTransform ct = des.CreateEncryptor();
                byte[] input = Encoding.Unicode.GetBytes(PlainText);
                return ct.TransformFinalBlock(input, 0, input.Length);
            }
            public string Decryption(string CypherText, string key)
            {
                byte[] b = Convert.FromBase64String(CypherText);
                TripleDES des = CreateDes(key);
                ICryptoTransform ct = des.CreateDecryptor();
                byte[] output = ct.TransformFinalBlock(b, 0, b.Length);
                return Encoding.Unicode.GetString(output);
            } 
        }

    The message gets encrypted properly but the image isnt saved n gives "parameter invalid" message for 

     Bitmap newBmp = new Bitmap(EncryptedSaveFileDialog.FileName);


    • Edited by Resh90 Monday, November 5, 2012 3:04 PM
    Monday, November 5, 2012 2:53 PM
  • Usually IV should be initialized with some value. Currently it contains zeroes.

    Also it is not clear what happens latter with your byte array returned from Encryption and how it becomes a string parameter for Decryption.


    • Edited by Viorel_MVP Monday, November 5, 2012 6:35 PM
    Monday, November 5, 2012 5:54 PM