编码字符串和基64 [英] Encoding strings to and from base-64
问题描述
我是从基地-64串试图连接code一些字符串来回我有truble,以获得正确的结果。
字符串文本= base64string .... //这里我有一个base-64字符串。
字节[] EN codedByte = System.Text.ASCIIEncoding.ASCII.GetBytes(文本);
字符串base64En codeD = Convert.ToBase64String(EN codedByte);如果(文字== base64En codeD)//如果新的EN codeD字符串等于其初始值
返回base64En codeD;
我已经试过我的方法可以做到这一点,我似乎并没有得到正确的结果。我与 System.Text.Encoding.Uni code
和 System.Text.Encoding.UTF8
尝试都
这可能是什么问题呢?有没有人有一个妥善的解决办法?
字符串文本= base64string .... //这里我有一个base-64字符串。
字节[] EN codedByte = System.Text.ASCIIEncoding.ASCII.GetBytes(文本);
字符串base64En codeD = Convert.ToBase64String(EN codedByte);
您是双编码字符串。你开始用一个base64字符串,得到的字节数,然后的连接code一遍的。如果你想比较,您将需要开始与原始字符串。
I'm trying to encode some strings back and forth from base-64 string and I'm having truble to get the right result.
string text = base64string.... //Here I have a base-64 string.
byte[] encodedByte = System.Text.ASCIIEncoding.ASCII.GetBytes(text);
string base64Encoded = Convert.ToBase64String(encodedByte);
if (text == base64Encoded) //If the new encoded string is equal to its original value
return base64Encoded;
I have tried my ways to do this and I don't seem to get the right result. I have tried both with System.Text.Encoding.Unicode
and System.Text.Encoding.UTF8
What could be the problem? Does anyone have a proper solution?
string text = base64string.... //Here I have a base-64 string.
byte[] encodedByte = System.Text.ASCIIEncoding.ASCII.GetBytes(text);
string base64Encoded = Convert.ToBase64String(encodedByte);
You are double encoding the string. You begin with a base64 string, get the bytes, and then encode it again. If you want to compare you will need to begin with the original string.
这篇关于编码字符串和基64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!