added getSha256WithSalt(byte[], byte[])
This commit is contained in:
parent
a615545adc
commit
efe31d4818
@ -31,7 +31,7 @@ class HashUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] charToBytes = Sys.charToBytes(username.toCharArray());
|
byte[] charToBytes = Sys.charToBytes16(username.toCharArray());
|
||||||
byte[] userNameWithSalt = Sys.concatBytes(charToBytes, saltBytes);
|
byte[] userNameWithSalt = Sys.concatBytes(charToBytes, saltBytes);
|
||||||
|
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ class HashUtil {
|
|||||||
*/
|
*/
|
||||||
public static
|
public static
|
||||||
byte[] getSha256(String string) {
|
byte[] getSha256(String string) {
|
||||||
byte[] charToBytes = Sys.charToBytes(string.toCharArray());
|
byte[] charToBytes = Sys.charToBytes16(string.toCharArray());
|
||||||
|
|
||||||
SHA256Digest sha256 = new SHA256Digest();
|
SHA256Digest sha256 = new SHA256Digest();
|
||||||
byte[] usernameHashBytes = new byte[sha256.getDigestSize()];
|
byte[] usernameHashBytes = new byte[sha256.getDigestSize()];
|
||||||
@ -71,4 +71,20 @@ class HashUtil {
|
|||||||
|
|
||||||
return hashBytes;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user