简体   繁体   English

这是 64 位编码的吗?

[英]Is this 64-bit Encoded?

All of the passwords in our User DB look like this where we have == at the end:我们的用户数据库中的所有密码看起来像这样,我们在末尾有 ==:

91F2FSEYrFOcabeHK/UfNw== 91F2FSEYrFOcabeHK/UfNw==

So how can I tell if this is 64-bit encoded?那么如何判断这是否是 64 位编码的呢? It has to be because I can decode using a decode 64-bit routine I have.一定是因为我可以使用我拥有的 64 位解码例程进行解码。

I am trying now to figure out how to decode a literal string to 64-bit..back to the xxxxxxxx== and here is my code:我现在正试图弄清楚如何将文字字符串解码为 64 位..返回 xxxxxxxx==,这是我的代码:

string passwordToEncrypt = "test";
byte[] passwordToBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(passwordToEncrypt);
result = Convert.ToBase64String(passwordToBytes);

Updated:更新:

I need the text test to come out in Base64 with the == at the end.我需要在 Base64 中出现文本测试,最后带有 ==。

you have a typo in there - so the above code does not compile, try你有一个错字 - 所以上面的代码不能编译,试试

        string passwordToEncrypte = "test";
        byte[] passwordToBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(passwordToEncrypte);
        string result = Convert.ToBase64String(passwordToBytes);

result contains now a "Base64"-encoded password and end with "=="... result现在包含一个“Base64”编码的密码并以“==”结尾...

BUT the above code works only for passwords containing ASCII ... if you want it to work with UTF8 passwords then change it to:但是上面的代码仅适用于包含ASCII的密码......如果你希望它与UTF8密码一起使用,请将其更改为:

        string passwordToEncrypte = "test";
        byte[] passwordToBytes = Encoding.UTF8.GetBytes(passwordToEncrypte);
        string result = Convert.ToBase64String(passwordToBytes);

to go back from Base64 to the original you need to do:到 go 从 Base64 回到原来的你需要做的:

        string Original = Encoding.UTF8.GetString (Convert.FromBase64String(result));

see http://msdn.microsoft.com/en-us/library/86hf4sb8.aspx请参阅http://msdn.microsoft.com/en-us/library/86hf4sb8.aspx
andhttp://msdn.microsoft.com/en-us/library/system.convert.tobase64string.aspxhttp://msdn.microsoft.com/en-us/library/system.convert.tobase64string.aspx
and http://msdn.microsoft.com/en-us/library/system.convert.frombase64string.aspxhttp://msdn.microsoft.com/en-us/library/system.convert.frombase64string.aspx

Base64 encoded string doesn't always end with a =, it will only end with one or two = if they are required to pad the string out to the proper length.For more details checkout following link Base64 编码的字符串并不总是以 = 结尾,如果需要将字符串填充到适当的长度,它只会以一个或两个 = 结尾。有关更多详细信息,请查看以下链接

Padding填充

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM