如何在不使用Convert.from64BaseString(strinput)的情况下以字节为单位转换"+"和"/"? [英] How to convert '+' and '/' in byte without using Convert.from64BaseString(strinput)?
本文介绍了如何在不使用Convert.from64BaseString(strinput)的情况下以字节为单位转换"+"和"/"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码用于url的加密和解密.
但是在解密中,convert.from64BaseString(strinput)
中会发生错误,因为它无法转换``+"和``/''.
My code is for encryption and decryption of url.
But in decryption an error occurs in convert.from64BaseString(strinput)
, because it fails to convert ''+'' and ''/'' .
How can I convert ''+''and ''/'' char in byte, without using convert.from64BaseString()
?
推荐答案
怎么办?转换两个字符都不应该失败,它们都使用默认的base64字符集: http://en.wikipedia.org/wiki /Base64 [ ^ ]
当我尝试时,效果很好:
What is the error? It should not fail to convert either character, they are both in teh default base64 character set: http://en.wikipedia.org/wiki/Base64[^]
When I try, it works fine:
string unicode = "ABCDEFG+/abcedfg";
byte[] ascii = System.Text.Encoding.ASCII.GetBytes(unicode);
string base64 = Convert.ToBase64String(ascii);
byte[] convertBack = Convert.FromBase64String(base64);
string regenerated = System.Text.Encoding.ASCII.GetString(convertBack);
Console.WriteLine(unicode);
Console.WriteLine(regenerated);
您的代码有何不同?
How is your code different?
我认为您误解了您的问题.我以前看过你的问题.
您的问题不是转换,而是将字符串作为url QueryString传递.
字符"+"不会作为查询字符串传递,您将获得一个空格.因此,您需要将其替换为其他字符(在附加查询字符串之前),例如,将@替换为+并执行链接(可能是您需要检查已具有@的字符串,替换为尚未包含在其中的字符)字符串,可以是替换字符,也可以在查询字符串中作为参数传递).在目标页面中,您可能需要将@替换为+.这样您将获得原始字符串,然后可以进行转换和比较.
Hi
I think you have misunderstood your problem. I have seen your question before.
Your problem is not converting, your problem is passing the string as a url QueryString.
the char ''+'' will not be passed as query string, you will get a blank space. So you need to replace it with other char (before appending the query string), for example replace + with @ and execute the link (may be you need to chk your string already having a @, replace with a char which is not already in the string, may be the replace char also can be passed as a parameter in the querystring). In the target page you may need to replace the @ with the + . So you will get the original string and then you can convert and compare.
这篇关于如何在不使用Convert.from64BaseString(strinput)的情况下以字节为单位转换"+"和"/"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文