无效的长度为Base-64字符数组,而解密 [英] Invalid length for a Base-64 char array while decryption
问题描述
我打通(解密)在某些情况下,以下异常,我无法准确识别的原因:
I get the following exception in some cases through (decryption) , and i can't recognize exactly the reason :
对于一个base-64字符数组的无效长度
Invalid length for a Base-64 char array
我的code:
public static string encodeSTROnUrl(string thisEncode)
{
if (null == thisEncode)
return string.Empty;
return HttpUtility.UrlEncode(Encrypt(thisEncode));
}
// string thisDecode = "3Dn%2bsJJPXprU4%3d"; //this is the value which cause the exception.
public static string decodeSTROnUrl(string thisDecode)
{
return Decrypt(HttpUtility.UrlDecode(thisDecode));
}
QueryStringEncryption.Cryptography.decodeSTROnUrl(Request.QueryString["val"].ToString());
这抛出异常的确切行是:
The exact line which throw the exception is :
Byte[] byteArray = Convert.FromBase64String(text);
我想我之前的加密和解密operation.but一些值仍然抛出这个异常后,通过固定编码和解码这个问题。
I thought i fix this problem by encoding and decoding before and after the encryption and the decryption operation.but some values still throw this exception .
请注意:我注意到一些奇怪的行为:
该ID作为发送到我的邮箱查询字符串是: N%2bsJJPXprU4%3D
和它的作品没有例外。
Note: i note some strange behavior :
the id as a query string sent to my mail is : n%2bsJJPXprU4%3d
and it works without exceptions ..
和谁的发送URL包含问题的用户 3DN%2bsJJPXprU4%3D
and the user who has the problem the sent url contains 3Dn%2bsJJPXprU4%3d
这是一个浏览器的问题?? !!
is this a browser problem ??!!
推荐答案
解码查询字符串值是当它解析为请求已经完成。尝试没有
HttpUtility.UrlDe code
Decoding the querystring values is done already when it's parsed into the Request. try without 'HttpUtility.UrlDecode'
public static string decodeSTROnUrl(string thisDecode)
{
return Decrypt(thisDecode);
}
这篇关于无效的长度为Base-64字符数组,而解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!