mirror of
https://github.com/emn178/js-sha256.git
synced 2026-08-12 20:32:16 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
189bb9b037 | ||
|
|
e35c679c2b | ||
|
|
bf155ab82f |
@@ -1,5 +1,15 @@
|
||||
# Change Log
|
||||
|
||||
## v0.9.0 / 2017-12-18
|
||||
### Fixed
|
||||
- incorrect result when first bit is 1 of bytes.
|
||||
|
||||
### Changed
|
||||
- throw error by Error oject. #13
|
||||
|
||||
### Added
|
||||
- TypeScript interfaces. #12
|
||||
|
||||
## v0.8.0 / 2017-11-19
|
||||
### Added
|
||||
- support for web worker.
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "js-sha256",
|
||||
"version": "0.8.0",
|
||||
"version": "0.9.0",
|
||||
"main": ["src/sha256.js"],
|
||||
"ignore": [
|
||||
"samples",
|
||||
|
||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
Vendored
+90
@@ -34,6 +34,63 @@ interface Hasher {
|
||||
array(): number[];
|
||||
}
|
||||
|
||||
interface Hmac {
|
||||
/**
|
||||
* Computes a Hash-based message authentication code (HMAC) using a secret key
|
||||
*
|
||||
* @param secretKey The Secret Key
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
(secretKey: string, message: Message): string;
|
||||
|
||||
/**
|
||||
* Create a hash object using a secret key.
|
||||
*
|
||||
* @param secretKey The Secret Key
|
||||
*/
|
||||
create(secretKey: string): Hasher;
|
||||
|
||||
/**
|
||||
* Create a hash object and hash message using a secret key
|
||||
*
|
||||
* @param secretKey The Secret Key
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
update(secretKey: string, message: Message): Hasher;
|
||||
|
||||
/**
|
||||
* Return hash in hex string.
|
||||
*
|
||||
* @param secretKey The Secret Key
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
hex(secretKey: string, message: Message): string;
|
||||
|
||||
/**
|
||||
* Return hash in ArrayBuffer.
|
||||
*
|
||||
* @param secretKey The Secret Key
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
arrayBuffer(secretKey: string, message: Message): ArrayBuffer;
|
||||
|
||||
/**
|
||||
* Return hash in integer array.
|
||||
*
|
||||
* @param secretKey The Secret Key
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
digest(secretKey: string, message: Message): number[];
|
||||
|
||||
/**
|
||||
* Return hash in integer array.
|
||||
*
|
||||
* @param secretKey The Secret Key
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
array(secretKey: string, message: Message): number[];
|
||||
}
|
||||
|
||||
interface Hash {
|
||||
/**
|
||||
* Hash and return hex string.
|
||||
@@ -53,6 +110,39 @@ interface Hash {
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
update(message: Message): Hasher;
|
||||
|
||||
/**
|
||||
* Return hash in hex string.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
hex(message: Message): string;
|
||||
|
||||
/**
|
||||
* Return hash in ArrayBuffer.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
arrayBuffer(message: Message): ArrayBuffer;
|
||||
|
||||
/**
|
||||
* Return hash in integer array.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
digest(message: Message): number[];
|
||||
|
||||
/**
|
||||
* Return hash in integer array.
|
||||
*
|
||||
* @param message The message you want to hash.
|
||||
*/
|
||||
array(message: Message): number[];
|
||||
|
||||
/**
|
||||
* HMAC interface
|
||||
*/
|
||||
hmac: Hmac;
|
||||
}
|
||||
|
||||
export var sha256: Hash;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "js-sha256",
|
||||
"version": "0.8.0",
|
||||
"version": "0.9.0",
|
||||
"description": "A simple SHA-256 / SHA-224 hash function for JavaScript supports UTF-8 encoding.",
|
||||
"main": "src/sha256.js",
|
||||
"devDependencies": {
|
||||
|
||||
+9
-9
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* [js-sha256]{@link https://github.com/emn178/js-sha256}
|
||||
*
|
||||
* @version 0.8.0
|
||||
* @version 0.9.0
|
||||
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
||||
* @copyright Chen, Yi-Cyuan 2014-2017
|
||||
* @license MIT
|
||||
@@ -88,7 +88,7 @@
|
||||
return crypto.createHash(algorithm).update(message, 'utf8').digest('hex');
|
||||
} else {
|
||||
if (message === null || message === undefined) {
|
||||
throw ERROR;
|
||||
throw new Error(ERROR);
|
||||
} else if (message.constructor === ArrayBuffer) {
|
||||
message = new Uint8Array(message);
|
||||
}
|
||||
@@ -169,16 +169,16 @@
|
||||
if (type !== 'string') {
|
||||
if (type === 'object') {
|
||||
if (message === null) {
|
||||
throw ERROR;
|
||||
throw new Error(ERROR);
|
||||
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
||||
message = new Uint8Array(message);
|
||||
} else if (!Array.isArray(message)) {
|
||||
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
|
||||
throw ERROR;
|
||||
throw new Error(ERROR);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw ERROR;
|
||||
throw new Error(ERROR);
|
||||
}
|
||||
notString = true;
|
||||
}
|
||||
@@ -257,7 +257,7 @@
|
||||
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
|
||||
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
||||
}
|
||||
blocks[14] = this.hBytes << 3 | this.bytes >> 29;
|
||||
blocks[14] = this.hBytes << 3 | this.bytes >>> 29;
|
||||
blocks[15] = this.bytes << 3;
|
||||
this.hash();
|
||||
};
|
||||
@@ -453,16 +453,16 @@
|
||||
} else {
|
||||
if (type === 'object') {
|
||||
if (key === null) {
|
||||
throw ERROR;
|
||||
throw new Error(ERROR);
|
||||
} else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) {
|
||||
key = new Uint8Array(key);
|
||||
} else if (!Array.isArray(key)) {
|
||||
if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) {
|
||||
throw ERROR;
|
||||
throw new Error(ERROR);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw ERROR;
|
||||
throw new Error(ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user