C#读回加密的密码 [英] C# Reading back encrypted passwords

查看:114
本文介绍了C#读回加密的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码将密码保存到注册表中,我如何将其转换回来?下面的代码不是我的,但它加密好。



谢谢

 使用System.Security.Cryptography; 

public static string EncodePasswordToBase64(string password)
{byte [] bytes = Encoding.Unicode.GetBytes(password);
byte [] dst = new byte [bytes.Length];
byte [] inArray = HashAlgorithm.Create(SHA1)。ComputeHash(dst);
return Convert.ToBase64String(inArray);


解决方案

SHA1是哈希算法,而不是加密算法。哈希算法是一种单向函数,它将数据转换为该数据的哈希值,但原始数据无法从哈希中获取。加密算法是一种双向函数,可将数据转换为加密数据,然后可将加密数据转换回原始数据。

I'm using the code below to save a password to the registry, how do I convert it back? The code below isn't mine but it encrypts well.

Thanks

using System.Security.Cryptography;

public static string EncodePasswordToBase64(string password)
{  byte[] bytes   = Encoding.Unicode.GetBytes(password);
   byte[] dst     = new byte[bytes.Length];
   byte[] inArray = HashAlgorithm.Create("SHA1").ComputeHash(dst);
   return Convert.ToBase64String(inArray);
}

解决方案

SHA1 is a hash algorithm, not an encryption algorithm. A hash algorithm is a one-way function which transforms data into a hash of that data, but the original data cannot be gotten back from the hash. An encryption algorithm is a two-way function which transforms data into encrypted data, and the encrypted data can then be transformed back into the original data.

这篇关于C#读回加密的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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