yutent 57783c1d01 | ||
---|---|---|
src | ||
.gitignore | ||
.npmignore | ||
.prettierrc.yaml | ||
Readme.md | ||
Readme_EN.md | ||
build.js | ||
package.json |
Readme_EN.md
crypto.js browser edition, which provides regular using
Thanks these two libraries:
- 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.
- 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/latest/md5.js'
// base64
import { base64encode, base64decode } from '//unpkg.com/crypto.web.js/latest/base64.js'
import { sha1, hmac } from '//unpkg.com/crypto.web.js/latest/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 throughFileReader
, and theBlob
object of the new browser also has anarraybuffer
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.