Password encryption/decryption code in .NET

后端 未结 9 994
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 00:37

I want simple encryption and decryption of password in C#. How to save the password in encrypted format in database and retrieve as original format by decryption?

9条回答
  •  有刺的猬
    2020-11-29 01:30

    EDIT: this is a very old answer. SHA1 was deprecated in 2011 and has now been broken in practice. https://shattered.io/ Use a newer standard instead (e.g. SHA256, SHA512, etc).

    If your answer to the question in my comment is "No", here's what I use:

        public static byte[] HashPassword(string password)
        {
            var provider = new SHA1CryptoServiceProvider();
            var encoding = new UnicodeEncoding();
            return provider.ComputeHash(encoding.GetBytes(password));
        }
    

提交回复
热议问题