diff --git a/Readme.md b/Readme.md index af3aa59..ded9520 100644 --- a/Readme.md +++ b/Readme.md @@ -1,5 +1,6 @@ ## crypto.js浏览器版本,提供常用的加密封装 +[English Readme](./Readme_EN.md) 感谢以下2个优秀的开源库: @@ -11,8 +12,8 @@ ```js -import crypto, { md5, base64encode } from '//unpkg.com/crypto.web.js/dist/index.js' -import crypto, { md5, base64encode } from '//jscdn.ink/crypto.web.js/latest/index.js' // 大陆用户可使用此加速地址 +// 多合一 +import { sha1, hmac, md5, base64encode } from '//jscdn.ink/crypto.web.js/latest/index.js' // 大陆用户可使用此加速地址 import { md5, md5Sum } from '//jscdn.ink/crypto.web.js/latest/md5.js' @@ -23,7 +24,7 @@ import { base64encode, base64decode } from '//jscdn.ink/crypto.web.js/latest/bas ### APIs -#### 1. md5(str``) +#### 1. md5(str`|`) > 常规的md5函数, 可对字符串(数字类型也可以), 进行加密。如果要对一个超级大的文本进行md5求值的话, 建议改成下面的 md5Sum() diff --git a/Readme_EN.md b/Readme_EN.md new file mode 100644 index 0000000..accf12c --- /dev/null +++ b/Readme_EN.md @@ -0,0 +1,80 @@ +## crypto.js browser edition, which provides regular using + +[中文 Readme](./Readme.md) + +Thanks these two libraries: + +1. [spark-md5](https://github.com/satazor/js-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](https://github.com/beatgammit/base64-js), 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. + + +```js +// 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`|`) +> regular md5 function, you can use to calculate a small string(<100MB). + + +#### 2. md5Sum(ab``) +> 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``) +> Base64 encoding, supports Chinese. + + +#### 4. base64decode(str``) +> Base64 decoding. + + +#### 5. uuid() +> Generate a unique 24-bit random string. Only guarantees uniqueness on a single machine. + + +#### 6. ab2hex(ab``) +> Convert an `arraybuffer` object to a hexadecimal string. + + +#### 7. ab2bin(ab``) +> Convert an `arraybuffer` object to a Binary string. + + +#### 8. sha1(str``) +> 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``) +> 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``) +> 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``, data`||`) +> 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``, data`||`, key`|`, outEncode``) +> 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. diff --git a/package.json b/package.json index 77c671a..5ae7e75 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "crypto.web.js", - "version": "1.0.2", + "version": "1.0.3", "type": "module", "main": "dist/index.js", "files": [