c# - Hash algorithm SHA256, is my method secure? How do I add a salt value to make more secure -
i quite new cryptography , want head around hashing algorithms.
i have sources following create hashed version of password, can stored in database.
public static string hashpasswordgenerator(string password) { system.security.cryptography.sha256managed crypt = new system.security.cryptography.sha256managed(); stringbuilder hash = new stringbuilder(); byte[] cry = crypt.computehash(encoding.utf8.getbytes(password), 0, encoding.utf8.getbytecount(password)); return convert.tobase64string(cry); }
my example user user1
password password1
, returns hashed version of gve/3j2k+3kkof62ardujtyq/5tvqz4fi2puqj3+4d0=
my questions are:
- is secure?
- should add salt this? if can show me simple example not understand how salt generated match password every time?
- if has hashpasswordgenerator method reverse engineer password?
thanks in advance.
is secure?
not if you're using sha2 without salt. (not saying sha2 can reversed easily)
should add salt this?
yes.
if can show me simple example
rngcryptoserviceprovider rngcsp = new rngcryptoserviceprovider(); var salt = new byte[32]; rngcsp.getbytes(salt); // fill buffer random values
as not understand how salt generated match password every time
you must save salt (which must unique each password) along hashed(password+salt).
if has
hashpasswordgenerator
method reverse engineer password?
yes if it's dictionary password , if you're not using salts. otherwise no (for foreseeable future) since hashes supposed hard reverse.
btw instead of trying reinvent wheel should using pbkdf2 password hashing needs since has work factor can slow down brute force attacks (number of iteration).
Comments
Post a Comment