Skip to content

Instantly share code, notes, and snippets.

@sergeevabc
Last active August 29, 2015 14:07
Show Gist options
  • Save sergeevabc/227b6c4d405a3c392ec3 to your computer and use it in GitHub Desktop.
Save sergeevabc/227b6c4d405a3c392ec3 to your computer and use it in GitHub Desktop.
PBKDF2_HMAC_SHA256/index.html
<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>
@sergeevabc
Copy link
Author

Разработчик пояснил, почему хэши разные и как это исправить. Спасибо ему (Дмитрию).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment