How to hash a password

后端 未结 9 706
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 14:49

I\'d like to store the hash of a password on the phone, but I\'m not sure how to do it. I can only seem to find encryption methods. How should the password be hashed properl

9条回答
  •  悲哀的现实
    2020-11-22 15:34

    UPDATE: THIS ANSWER IS SERIOUSLY OUTDATED. Please use the recommendations from the https://stackoverflow.com/a/10402129/251311 instead.

    You can either use

    var md5 = new MD5CryptoServiceProvider();
    var md5data = md5.ComputeHash(data);
    

    or

    var sha1 = new SHA1CryptoServiceProvider();
    var sha1data = sha1.ComputeHash(data);
    

    To get data as byte array you could use

    var data = Encoding.ASCII.GetBytes(password);
    

    and to get back string from md5data or sha1data

    var hashedPassword = ASCIIEncoding.GetString(md5data);
    

提交回复
热议问题