0

I am trying to Encrypt / Decrypt data to use in the Querystring.

Most of the time, the encrypted data ends with the "equal" symbol '='

The following are some examples of encrypted string

 1 - LS07D43u6Hs= 
 2 - oHPgq6hz0A0=  
 3 - 4ugeuARQvXw=   
 abc - gZfrQVAk9Ic=  
 encode me - RfSQYXX1P4MU7LhMsfsG8w==

I copied the codes from here and changed a bit.

http://www.deltasblog.co.uk/code-snippets/basic-encryptiondecryption-c/

        byte[] inputArray = UTF8Encoding.UTF8.GetBytes("encode me");
        TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
        tripleDES.Key = UTF8Encoding.UTF8.GetBytes("abcd123456Idlaaz");
        tripleDES.Mode = CipherMode.ECB;
        tripleDES.Padding = PaddingMode.PKCS7;
        ICryptoTransform cTransform = tripleDES.CreateEncryptor();
        byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length);
        tripleDES.Clear();


        Response.Write(Convert.ToBase64String(resultArray, 0, resultArray.Length)); 

I tried to change the Key, PaddingMode, CipherMode, but no luck. It always return = at the end. Please help me.

TTCG
  • 8,805
  • 31
  • 93
  • 141

1 Answers1

3

the equal sign at the end isnt beign generated by the encypting algo.
Its a standard procedure to pad when creating a base 64 encoded string. you can find more info at Why does a base64 encoded string have an = sign at the end

also this ending mechanism is very nicely explained here http://en.wikipedia.org/wiki/Base64

Community
  • 1
  • 1
Parv Sharma
  • 12,581
  • 4
  • 48
  • 80
  • Is it possible that it's going to add "&" sign in the encrypted string? I am going to use that encrypted string in the QueryString. So, it must not have & sign. – TTCG Oct 30 '13 at 09:42
  • 1
    the typical solution is to url encode the query string and then use it.. when you wanna read it just url decode it – Parv Sharma Oct 30 '13 at 09:53