added getSha256WithSalt(byte[], byte[])

This commit is contained in:
nathan 2017-08-01 00:54:17 +02:00
parent a615545adc
commit efe31d4818
1 changed files with 18 additions and 2 deletions

View File

@ -31,7 +31,7 @@ class HashUtil {
return null;
}
byte[] charToBytes = Sys.charToBytes(username.toCharArray());
byte[] charToBytes = Sys.charToBytes16(username.toCharArray());
byte[] userNameWithSalt = Sys.concatBytes(charToBytes, saltBytes);
@ -48,7 +48,7 @@ class HashUtil {
*/
public static
byte[] getSha256(String string) {
byte[] charToBytes = Sys.charToBytes(string.toCharArray());
byte[] charToBytes = Sys.charToBytes16(string.toCharArray());
SHA256Digest sha256 = new SHA256Digest();
byte[] usernameHashBytes = new byte[sha256.getDigestSize()];
@ -71,4 +71,20 @@ class HashUtil {
return hashBytes;
}
public static
byte[] getSha256WithSalt(byte[] bytes, byte[] saltBytes) {
if (bytes == null || saltBytes == null) {
return null;
}
byte[] bytesWithSalt = dorkbox.util.Sys.concatBytes(bytes, saltBytes);
SHA256Digest sha256 = new SHA256Digest();
byte[] usernameHashBytes = new byte[sha256.getDigestSize()];
sha256.update(bytesWithSalt, 0, bytesWithSalt.length);
sha256.doFinal(usernameHashBytes, 0);
return usernameHashBytes;
}
}