如何在C#中将字节转换为可读字符串? [英] How to convert byte to readable string in C#?

查看:66
本文介绍了如何在C#中将字节转换为可读字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  foreach (DataRow row  in  dt.Rows)
{
username = row [ USERNAME]。ToString();
byte [] bytePassword =( byte [])row [ PASSWORD];
decryptPassword = Encoding.Default.GetString(bytePassword, 0 ,bytePassword.Length-1);

密码=行[ PASSWORD]。ToString();
}

string result = 这是我的 +用户名+ action ... +密码+ + decryptPassword;

结果是

这是我的TEST动作... System.Byte []:?‡½?³wã.çr...)©K ??‡?n‰,ò¹5? ÌE_0Ây™? ?÷X?Xp @hdž',MÛÀy(ÓÊÕþB

我似乎无法使用System.Text.Encoding解码密码



我需要解密PASSWORD然后再加密它才能保存在数据库中。



我尝试过: < br $>


stackoverflow .com

social.msdn.microsoft.com

stackoverflow.com

解决方案

请参阅简单解释安全密码验证 [ ^ ]。


什么让你认为密码是加密的?

它不应该是:这是不安全的,几乎与以纯文本存储一样糟糕。

和System.Text.Encoding没有任何关于加密的东西 - 这是一个翻译,就是全部。

密码应该是哈希的,而不是加密的 - 特别是因为它不能反转回原始输入。

请参阅:密码存储:如何操作。 [ ^

foreach (DataRow row in dt.Rows)
{
   username = row["USERNAME"].ToString();
   byte[] bytePassword = (byte[])row["PASSWORD"];
   decryptPassword = Encoding.Default.GetString(bytePassword, 0, bytePassword.Length-1);

   password = row["PASSWORD"].ToString();                    
}

string result = "This is my "+ username +" action..." + password + " : " + decryptPassword;

The result is

This is my TEST action...System.Byte[] : ‡½³wã.ç r…)©K‡n‰‚ò¹5y ÌE_0Ây™ âGâ)÷XXp@hdž‘,MÛÀy(ÓÊÕþB

I cannot seem to decode the password using System.Text.Encoding

I need to decrypt the PASSWORD then encrypt it again just so it could be saved in the database.

What I have tried:

stackoverflow.com
social.msdn.microsoft.com
stackoverflow.com

解决方案

See Secure Password Authentication Explained Simply[^].


What makes you think that a password is encrypted?
It shouldn't be: that's insecure, nearly as bad as storing it in plain text.
And System.Text.Encoding has nothing whatsoever to do with encryption - it's a translation, is all.
Passwords should be hashed, not encrypted - specifically so thay cannot be "reversed" back to the original input.
See here: Password Storage: How to do it.[^]


这篇关于如何在C#中将字节转换为可读字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆