Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top