dchest / fast-sha256-js Goto Github PK
View Code? Open in Web Editor NEWSHA-256, HMAC, HKDF and PBKDF2 implementation for JavaScript/TypeScript with typed arrays for modern browsers and Node.js
License: The Unlicense
SHA-256, HMAC, HKDF and PBKDF2 implementation for JavaScript/TypeScript with typed arrays for modern browsers and Node.js
License: The Unlicense
In the README, this link does not point to the split off nacl.util project page.
https://github.com/dchest/fast-sha256-js/blame/master/README.md#L35
I wonder if an input type check, say in Hash.prototype.update(data), would be appropriate for idiots like me who just assume that a string is fine :)
Hash.prototype.update = function (data, dataLength) {
if (typeof data === "string") {
throw new Error("Input data should be Uint8Array");
}
I got much better results when I converted my strings to Uint8Array after noticing that my result was different than that produced by sha256sum at the command line.
pbkdf2 always gives me the same result regardless of the password:
sha256.pbkdf2('b', 'salt', 10, 32).join(',')
"234,39,191,6,86,158,63,177,246,157,96,178,195,13,125,54,91,1,37,107,241,3,140,34,21,102,65,171,57,106,121,67"
sha256.pbkdf2('a', 'salt', 10, 32).join(',')
"234,39,191,6,86,158,63,177,246,157,96,178,195,13,125,54,91,1,37,107,241,3,140,34,21,102,65,171,57,106,121,67"
What am I doing wrong?

Дмитрий,
password
, salt
, 1000
, 20
Asmcrypto: 632c2812e46d4604102ba7618e9d6d7d2f8128f6
DmitryChe: d1035cbdf15c9f80ef8c9fc01ae5ec06552943de
Хэши отличаются. Почему?
I am trying to get corresponding values between JavaScript code and Java code. When that didn't happen, I went looking for test vectors, and added this function to my JavaScript, which fails to produce the expected output for the first test vector.
function doTestVectors() {
// Test vectors from https://stackoverflow.com/questions/5130513/pbkdf2-hmac-sha2-test-vectors
result1 = toHexString(sha256.pbkdf2("password", "salt", 1, 32));
expected1 = "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b";
if (result1 != expected1)
{
alert("Test failed. result1=" + result1);
}
}
It produces:
Test failed. result1=a4a11ce5fbe8f96bf3028035286c2c9274cd4259cbc224e37a73d971923903d3
Perhaps you could add these known good test vectors to the code and then hopefully also get a match?
Some problem on Chromium-based browsers. (Maybe in other too.)
For two different passwords returns same result.
For example:
console.log(sha256.pbkdf2('dsddsdsds1', '', 0, 32));
console.log(sha256.pbkdf2('sddsdsdse1', '', 0, 32));
I was trying to use the sha256.hmac function to generate hmac sha256 hash, but I got some garbled code.
//convert String to Uint8Array
var msg = new TextEncoder("utf-8").encode("/v2/radios?page=1&size=10&catalog=all:7690d85d-7777-2930-040c-9241b52682ab");
var key = new TextEncoder("utf-8").encode("q23IN6hB7p");
var hash = sha256.hmac(key, msg);
//convert Uint8Array to String
console.log(new TextDecoder("utf-8").decode(hash)); // result is garbled code: gUm7_���������)���V�Ύ����kb�l�T
version: v1.0.0
browser: Chrome 62
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.