C#中的密码加密? [英] Password encryption in C#?

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

问题描述

如何在 C# 中加密和解密密码?感谢您的帮助.

How can I encrypt and decrypt passwords in C#? Thanks for any help.

推荐答案

首先,您实际上不会将加密的密码保存在任何地方,而是执行单向哈希(例如,SHA) 存储该哈希值.然后,当您向用户询问密码时,您执行相同的哈希.如果新的哈希值与存储的哈希值匹配,那么您就有了匹配项.

First, you're not actually going to save the encrypted password anywhere, rather you'd perform a one-way hash (e.g., SHA) store that hash. Then when you challenge a user for his password, you perform the same hash. If the new hash matches the stored hash, you've got a match.

散列和加密的区别在于,使用加密可以恢复原始文本,而使用散列则不能.

The difference between a hash and encryption is that with encryption, you can recover the original text, where with a hash you cannot.

阅读 SHA(安全散列算法)和其他散列算法.这应该会给你一个好的开始.

Read up on SHA (Secure Hashing Algorithm) and other hashing algorithms. This should give you a good start.

更好的是,了解内置的 Membership API.网.实现起来几乎是微不足道的,它可以为您管理所有关于用户 ID、密码、登录、注销以及很多的不愉快.

Even better, learn about the built in Membership API in .NET. It's almost trivial to implement and it manages all that unpleasantness about userid's, passwords, logging in, logging out and a lot more for you.

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

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