About url encryption settings

 Another function in the recent project is to nest third-party addresses, so I got an https domain name and added an ifram nesting, but the problem appeared.

When the url jumps, the url address bar is alsoThere will be a third-party url address, even if it is passed as a parameter, but it is not allowed, then the problem comes,

 How to encrypt the url can't see what it is, the following is the encodeurl,

 public static string Encode(string str, string key)
    {


        DESCryptoServiceProvider provider = new DESCryptoServiceProvider();


        provider.Key = Encoding.ASCII.GetBytes(key.Substring(0, 8));


        provider.IV = Encoding.ASCII.GetBytes(key.Substring(0, 8));


        byte[] bytes = Encoding.UTF8.GetBytes(str);


        MemoryStream stream = new MemoryStream();


        CryptoStream stream2 = new CryptoStream(stream, provider.CreateEncryptor(), CryptoStreamMode.Write);


        stream2.Write(bytes, 0, bytes.Length);


        stream2.FlushFinalBlock();


        StringBuilder builder = new StringBuilder();


        foreach (byte num in stream.ToArray())
        {


            builder.AppendFormat("{0:X2}", num);


        }


        stream.Close();


        return builder.ToString();


    }

It is useless to say more, call directly

 string posturl = Encode(posturl.Trim(), "Rainight").Trim();

knock off.

Here is the decryption:

 public string Decrypt(string pToDecrypt, string sKey)
    {


        DESCryptoServiceProvider des = new DESCryptoServiceProvider();






        //Put the input string into the byte array     


        byte[] inputByteArray = new byte[pToDecrypt.Length / 2];


        for (int x = 0 ; x < pToDecrypt.Length / 2; x++)
        {


            int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));


            inputByteArray[x] = (byte)i;


        }






        //Create encryption The key and offset of the object, this value is important and cannot be modified     


        des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);


        des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);


        MemoryStream ms = new MemoryStream();


        CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);


        //Flush the data through the crypto stream into the memory stream     


        cs.Write(inputByteArray, 0, inputByteArray.Length);


        cs.FlushFinalBlock() ;






        //Get the decrypted data back from the memory stream     


        //Create a StringBuild object, CreateDecrypt uses a stream object, and the decrypted text must be turned into a stream object     


        StringBuilder ret = new StringBuilder();






        return System.Text.Encoding. Default.GetString(ms.ToArray());


    }     



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325996419&siteId=291194637