yutent 0d9612576c change repo 2023-09-26 11:08:09 +08:00
src 优化hash(), hmac()的传值 2023-06-25 11:30:36 +08:00
.gitignore 1.0.0 2023-02-13 19:18:15 +08:00
.npmignore 1.0.0 2023-02-13 19:18:15 +08:00
.prettierrc.yaml 1.0.0 2023-02-13 19:18:15 +08:00
Readme.md 增加英文说明 2023-09-26 11:01:54 +08:00
Readme_EN.md 1.0.3 2023-09-26 11:04:14 +08:00
build.js 1.0.0 2023-02-13 19:18:15 +08:00
package.json change repo 2023-09-26 11:08:09 +08:00

Readme_EN.md

crypto.js browser edition, which provides regular using

中文 Readme

Thanks these two libraries:

  1. spark-md5, After some testing, this is indeed the highest performing version in the pure JS version. It has been introduced into this warehouse and adjusted to be used in ESM mode.
  2. base64, Fully supported base64 library, which supports encoding Chinese characters compared to the native btoa() method.

These two libraries are included in index.js. If you have specific requirements on size, you can use them separately.

// all in one
import { sha1, hmac, md5, base64encode } from '//unpkg.com/crypto.web.js/dist/index.js'

// md5
import { md5, md5Sum } from '//unpkg.com/crypto.web.js/dist/md5.js'

// base64
import { base64encode, base64decode } from '//unpkg.com/crypto.web.js/dist/base64.js'

import { sha1, hmac } from '//unpkg.com/crypto.web.js/dist/crypto.js'

APIs

1. md5(str<String>|<Number>)

regular md5 function, you can use to calculate a small string(<100MB).

2. md5Sum(ab<ArrayBuffer>)

you can use this to calculate a large data. Need an ArrayBuffer object which can get the value through FileReader , and the Blob object of the new browser also has an arraybuffer prototype method。

3. base64encode(str<String>)

Base64 encoding, supports Chinese.

4. base64decode(str<String>)

Base64 decoding.

5. uuid()

Generate a unique 24-bit random string. Only guarantees uniqueness on a single machine.

6. ab2hex(ab<ArrayBuffer>)

Convert an arraybuffer object to a hexadecimal string.

7. ab2bin(ab<ArrayBuffer>)

Convert an arraybuffer object to a Binary string.

8. sha1(str<String>)

Calculate the sha1 value of the specified string.

Note: The return value of this method is not a string, but a Promise object.

9. sha256(str<String>)

Calculate the sha256 value of the specified string.

Note: The return value of this method is not a string, but a Promise object.

10. sha512(str<String>)

Calculate the sha512 value of the specified string.

Note: The return value of this method is not a string, but a Promise object.

11. hash(algorithm<String>, data<String>|<ArrayBuffer>|<Uint8Array>)

Hash algorithm, used to implement fuzzy processing of some important data, to achieve the purpose of hiding plaintext. The above sha1, sha256, etc., are actually based on this re-encapsulation result; algorithm, optional values are: SHA-1, SHA-256, SHA-384, SHA-512.

Note: The return value of this method is not a string, but a Promise object.

12. hmac(algorithm<String>, data<String>|<ArrayBuffer>|<Uint8Array>, key<String>|<Uint8Array>, outEncode<String>)

HMAC algorithm, which is a combination of a hash algorithm and a key to prevent the destruction of signature integrity. Compared with the above hash algorithm, it has an additional key parameter.

Note: The return value of this method is not a string, but a Promise object.

浏览器端的加密库
JavaScript 100%