这个加密的QueryString的问题是什么 - Base-64 char数组的长度无效

时间:2021-09-06 18:30:16

I am encrypting a text and sending it via QueryString.

我正在加密文本并通过QueryString发送它。

"8ZnSq13yv2yYVDsehDnNUNp/yIFqsAQh4XNPbV1eLMpk/dMWpc/YnMMEBy29MlgcYqpV2XPOf/Rpiz5S85VN/fkLbGTCkL/clBHh983Cp s="

The Decrypt Function is given Below

Decrypt函数如下所示

public static string Decrypt(string stringToDecrypt)//Decrypt the content
{
    try
    {
        byte[] key = Convert2ByteArray(DESKey);
        byte[] IV = Convert2ByteArray(DESIV);
        int len = stringToDecrypt.Length;
        byte[] inputByteArray = Convert.FromBase64String(stringToDecrypt);

        DESCryptoServiceProvider des = new DESCryptoServiceProvider();
        MemoryStream ms = new MemoryStream(); 

        CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
        cs.Write(inputByteArray, 0, inputByteArray.Length);

        cs.FlushFinalBlock();

        Encoding encoding = Encoding.UTF8; return encoding.GetString(ms.ToArray());
    }
    catch (System.Exception ex)
    {
        throw ex;
    }
}

What should I do to resolve this issue?

我该怎么做才能解决这个问题?

4 个解决方案

#1


The 3rd last character is a space. I'm guessing that it was a + in the original before it was put on the query string. + is a special character on URL representing a space, so the QueryString is converting this to a space on you.

第3个最后一个字符是空格。我猜它在放入查询字符串之前是原始的+。 +是表示空格的URL上的特殊字符,因此QueryString将其转换为您的空间。

Try passing your Base64 string through

尝试传递Base64字符串

Server.UrlEncode(string); 

before redirecting & that will properly escape the + into a %urlchar and then pass it through

在重定向之前,它会将+正确地转义为%urlchar然后传递给它

Server.UrlDecode(string);

before parsing it on teh other side

在解析它之前

#2


I see a space at the end between p and s. That is not an allowed character in a base64 string.

我在p和s之间看到了一个空格。这不是base64字符串中允许的字符。

#3


The problem is likely that your string has characters that have special meaning on the request query. '/' , '=', and ' ' for instance.

问题可能是您的字符串具有在请求查询中具有特殊含义的字符。例如'/','='和''。

You can encode the string prior to sending, or better yet, add it to the form body of the request and send it that way instead of the query string.

您可以在发送之前对字符串进行编码,或者更好的是,将其添加到请求的表单主体并以该方式而不是查询字符串发送。

#4


Looks a character short to me... Base64 strings' length should be divisible by 4, padded by trailing '=' if necessary - are you missing a trailing '=', i.e. should it be "8ZnSq13yv2yYVDsehDnNUNp/yIFqsAQh4XNPbV1eLMpk/dMWpc/YnMMEBy29MlgcYqpV2XPOf/Rpiz5S85VN/fkLbGTCkL/clBHh983Cps=="?

看起来对我来说很短的一个字符... Base64字符串的长度应该可以被4整除,如果有必要用尾随'='填充 - 你是否缺少尾随'=',即它应该是“8ZnSq13yv2yYVDsehDnNUNp / yIFqsAQh4XNPbV1eLMpk / dMWpc / YnMMEBy29MlgcYqpV2XPOf / Rpiz5S85VN / fkLbGTCkL / clBHh983Cps ==“?

#1


The 3rd last character is a space. I'm guessing that it was a + in the original before it was put on the query string. + is a special character on URL representing a space, so the QueryString is converting this to a space on you.

第3个最后一个字符是空格。我猜它在放入查询字符串之前是原始的+。 +是表示空格的URL上的特殊字符,因此QueryString将其转换为您的空间。

Try passing your Base64 string through

尝试传递Base64字符串

Server.UrlEncode(string); 

before redirecting & that will properly escape the + into a %urlchar and then pass it through

在重定向之前,它会将+正确地转义为%urlchar然后传递给它

Server.UrlDecode(string);

before parsing it on teh other side

在解析它之前

#2


I see a space at the end between p and s. That is not an allowed character in a base64 string.

我在p和s之间看到了一个空格。这不是base64字符串中允许的字符。

#3


The problem is likely that your string has characters that have special meaning on the request query. '/' , '=', and ' ' for instance.

问题可能是您的字符串具有在请求查询中具有特殊含义的字符。例如'/','='和''。

You can encode the string prior to sending, or better yet, add it to the form body of the request and send it that way instead of the query string.

您可以在发送之前对字符串进行编码,或者更好的是,将其添加到请求的表单主体并以该方式而不是查询字符串发送。

#4


Looks a character short to me... Base64 strings' length should be divisible by 4, padded by trailing '=' if necessary - are you missing a trailing '=', i.e. should it be "8ZnSq13yv2yYVDsehDnNUNp/yIFqsAQh4XNPbV1eLMpk/dMWpc/YnMMEBy29MlgcYqpV2XPOf/Rpiz5S85VN/fkLbGTCkL/clBHh983Cps=="?

看起来对我来说很短的一个字符... Base64字符串的长度应该可以被4整除,如果有必要用尾随'='填充 - 你是否缺少尾随'=',即它应该是“8ZnSq13yv2yYVDsehDnNUNp / yIFqsAQh4XNPbV1eLMpk / dMWpc / YnMMEBy29MlgcYqpV2XPOf / Rpiz5S85VN / fkLbGTCkL / clBHh983Cps ==“?