GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Home Home
Brian Turek edited this page
Starting in v3.1, the jsSHA API changed with the deprecation of Usage of jsSHA typically involves three calls: // See below for constructor arguments const hash = new jsSHA(...); // .update() can be called multiple times hash.update("Stuff to hash") // The first argument can be one of "HEX" | "B64" | "BYTES" | "ARRAYBUFFER" | "UINT8ARRAY". hash.getHash("HEX") // For variable-length hashes (SHAKE, cSHAKE, and KMAC), you must specify the output length, in bits: // hash.getHash("HEX", { outputLen: 256 }) The constructor is most easily understood if you group jsSHA into four usage families: normal hashing, HMAC, cSHAKE, and KMAC. These all use a bag-of-options argument, The v3.1+ API options are built on a new "basic" type, called type GenericInputType = | { value: string; format: "TEXT"; encoding?: "UTF8" | "UTF16LE" | "UTF16BE"; } | { value: string; format: "B64" | "HEX" | "BYTES"; } | { value: ArrayBuffer; format: "ARRAYBUFFER"; } | { value: Uint8Array; format: "UINT8ARRAY"; }; In human speak:
This is when you wish to perform a SHA hash one or more times. In pseudo-code: // For future "TEXT" inputs: const textHash = new jsSHA( variant: "SHA-1" | "SHA-224" | "SHA-256" | "SHA-384" | "SHA-512" | "SHA3-224" | "SHA3-256" | "SHA3-384" | "SHA3-512" | "SHAKE128" | "SHAKE256", inputFormat: "TEXT", options: { encoding?: "UTF8" | "UTF16LE" | "UTF16BE"; numRounds?: number } ); // For future non-"TEXT" inputs: const nonTextHash = new jsSHA( variant: "SHA-1" | "SHA-224" | "SHA-256" | "SHA-384" | "SHA-512" | "SHA3-224" | "SHA3-256" | "SHA3-384" | "SHA3-512" | "SHAKE128" | "SHAKE256", inputFormat: "B64" | "HEX" | "BYTES" | "ARRAYBUFFER" | "UINT8ARRAY", options: { numRounds?: number } // True JavaScript Example: const hash = new jsSHA("SHA-1", "HEX", { numRounds: 1}); ); The only difference between the two is the omission of the The HMAC constructor is similar to the "normal" constructor but with the addition of an extra // For future "TEXT" inputs: const hash = new jsSHA( variant: "SHA-1" | "SHA-224" | "SHA-256" | "SHA-384" | "SHA-512" | "SHA3-224" | "SHA3-256" | "SHA3-384" | "SHA3-512", inputFormat: "TEXT", options: { encoding?: "UTF8" | "UTF16LE" | "UTF16BE"; hmacKey: GenericInputType } ); // For future non-"TEXT" inputs: const hash = new jsSHA( variant: "SHA-1" | "SHA-224" | "SHA-256" | "SHA-384" | "SHA-512" | "SHA3-224" | "SHA3-256" | "SHA3-384" | "SHA3-512", inputFormat: "B64" | "HEX" | "BYTES" | "ARRAYBUFFER" | "UINT8ARRAY", options: { hmacKey: GenericInputType } // True JavaScript Example: const hash = new jsSHA("SHA-1", "HEX", { hmacKey: { value: "Secret Key", format: "TEXT" } }); ); Again, the only difference between the two forms is the omission of the The CSHAKE constructor is similar to the "normal" constructor but with the addition of extra // For future "TEXT" inputs: const textHash = new jsSHA( variant: "CSHAKE128" | "CSHAKE256", inputFormat: "TEXT", options: { encoding?: "UTF8" | "UTF16LE" | "UTF16BE"; customization?: GenericInputType; funcName?: GenericInputType; } ); // For future non-"TEXT" inputs: const nonTextHash = new jsSHA( variant: "CSHAKE128" | "CSHAKE256", inputFormat: "B64" | "HEX" | "BYTES" | "ARRAYBUFFER" | "UINT8ARRAY", options: { customization?: GenericInputType; funcName?: GenericInputType; } ); // True JavaScript Example: const hash = new jsSHA("CSHAKE128", "HEX", { customization: { value: "My Tagged Application", format: "TEXT" } }); Again, the only difference between the two forms is the omission of the The KMAC constructor is similar to the "normal" constructor but with the addition of an extra // For future "TEXT" inputs: const textHash = new jsSHA( variant: "KMAC128" | "KMAC256", inputFormat: "TEXT", options: { encoding?: "UTF8" | "UTF16LE" | "UTF16BE"; customization?: GenericInputType; kmacKey: GenericInputType; } ); // For future non-"TEXT" inputs: const nonTextHash = new jsSHA( variant: "KMAC128" | "KMAC256", inputFormat: "B64" | "HEX" | "BYTES" | "ARRAYBUFFER" | "UINT8ARRAY", options: { customization?: GenericInputType; kmacKey: GenericInputType; } ); // True JavaScript Example: const hash = new jsSHA("KMAC128", "HEX", { customization: { value: "My Tagged Application", format: "TEXT" }, kmacKey: { value: "My Secret Key", format: "TEXT" } } ); Again, the only difference between the two forms is the omission of the Depending on the
For variable-length hashes (SHAKE, cSHAKE, and KMAC), For "B64" output type, For "HEX" output type, |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |