增加英文说明

master
yutent 2023-09-26 11:01:54 +08:00
parent 8eb2292a8c
commit 57783c1d01
3 changed files with 85 additions and 4 deletions

View File

@ -1,5 +1,6 @@
## crypto.js浏览器版本,提供常用的加密封装 ## crypto.js浏览器版本,提供常用的加密封装
[English Readme](./Readme_EN.md)
感谢以下2个优秀的开源库: 感谢以下2个优秀的开源库:
@ -11,8 +12,8 @@
```js ```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' 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 ### APIs
#### 1. md5(str`<String>`) #### 1. md5(str`<String>|<Number>`)
> 常规的md5函数, 可对字符串(数字类型也可以), 进行加密。如果要对一个超级大的文本进行md5求值的话, 建议改成下面的 md5Sum() > 常规的md5函数, 可对字符串(数字类型也可以), 进行加密。如果要对一个超级大的文本进行md5求值的话, 建议改成下面的 md5Sum()

80
Readme_EN.md Normal file
View File

@ -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`<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.

View File

@ -1,6 +1,6 @@
{ {
"name": "crypto.web.js", "name": "crypto.web.js",
"version": "1.0.2", "version": "1.0.3",
"type": "module", "type": "module",
"main": "dist/index.js", "main": "dist/index.js",
"files": [ "files": [