-
-
Save sergeevabc/227b6c4d405a3c392ec3 to your computer and use it in GitHub Desktop.
PBKDF2_HMAC_SHA256/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>PBKDF2-HMAC-SHA256 generation</title> | |
<script src="asmcrypto.js"></script> | |
<script src="sha256.min.js"></script> | |
<script> | |
// Set | |
var password = 'password', salt = 'salt', iterations = 1000, len = 20; | |
// Output is Uint8Array | |
var key = asmCrypto.PBKDF2_HMAC_SHA256.bytes(password, salt, iterations, len); | |
var key2 = sha256.pbkdf2(password, salt, iterations, len); | |
// Convert Uint8Array to Hex, from ASMCrypto | |
function bytes_to_hex(arr){ | |
var sz = ( arr.byteLength || arr.length ) / arr.length, | |
str = ''; | |
for ( var i = 0; i < arr.length; i++ ) { | |
var h = arr[i].toString(16); | |
if ( h.length < 2*sz ) str += '00000000000000'.substr( 0, 2*sz-h.length ); | |
str += h; | |
} | |
return str; | |
} | |
// Run | |
console.log("Asmcrypto: " + bytes_to_hex(key)); | |
console.log("DmitryChe: " + bytes_to_hex(key2)); | |
</script> | |
</head> | |
<body></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Разработчик пояснил, почему хэши разные и как это исправить. Спасибо ему (Дмитрию).