master
yutent 2024-07-17 12:21:49 +08:00
parent 54a8feb5ca
commit f26091f81c
2 changed files with 17 additions and 14 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "crypto.js", "name": "crypto.js",
"version": "3.2.1", "version": "3.2.2",
"description": "原生crypto加密模块的二次封装,简化常用加密函数的使用", "description": "原生crypto加密模块的二次封装,简化常用加密函数的使用",
"keywords": [ "keywords": [
"md5", "md5",

View File

@ -27,7 +27,7 @@ const MAC = (function (ns) {
return Math.random().toString(16).slice(-4) return Math.random().toString(16).slice(-4)
})(os.networkInterfaces()) })(os.networkInterfaces())
var __inc__ = 4096 let __inc__ = 4096
/** /**
* [base64encode base64编码] * [base64encode base64编码]
@ -35,7 +35,7 @@ var __inc__ = 4096
* @param {bool} urlFriendly [是否对URL友好, 默认否, 是则会把+转成-, /_] * @param {bool} urlFriendly [是否对URL友好, 默认否, 是则会把+转成-, /_]
*/ */
export function base64encode(str, urlFriendly) { export function base64encode(str, urlFriendly) {
var buf, str64 let buf, str64
if (Buffer.isBuffer(str)) { if (Buffer.isBuffer(str)) {
buf = str buf = str
@ -86,8 +86,8 @@ export function rand(len, forceNum) {
// 返回一个如下格式的 xxxxxxxx-xxxx-xxxx-xxxxxxxx 的唯一ID // 返回一个如下格式的 xxxxxxxx-xxxx-xxxx-xxxxxxxx 的唯一ID
export function uuid(pipe = '-') { export function uuid(pipe = '-') {
var str = crypto.randomUUID() let str = crypto.randomUUID()
var now = (~~(Date.now() / 1000)).toString(16) let now = (~~(Date.now() / 1000)).toString(16)
if (__inc__ > 65535) { if (__inc__ > 65535) {
__inc__ = 4096 __inc__ = 4096
@ -121,12 +121,13 @@ export function md5(str, encode) {
* @param {Str} file [文件路径] * @param {Str} file [文件路径]
*/ */
export function md5Sign(file) { export function md5Sign(file) {
if (fs.accessSync(file, fs.constants.R_OK)) { try {
var buf = fs.readFileSync(file) let buf = fs.readFileSync(file)
return hash('md5', buf) return hash('md5', buf)
} } catch (e) {
return null return null
} }
}
/** /**
* [sha1 sha1加密] * [sha1 sha1加密]
@ -149,12 +150,13 @@ export function sha1(str, encode) {
* @param {Str} file [文件路径] * @param {Str} file [文件路径]
*/ */
export function sha1Sign(file) { export function sha1Sign(file) {
if (fs.accessSync(file, fs.constants.R_OK)) { try {
var buf = fs.readFileSync(file) let buf = fs.readFileSync(file)
return hash('sha1', buf) return hash('sha1', buf)
} } catch (e) {
return null return null
} }
}
/** /**
* [sha256 sha256加密] * [sha256 sha256加密]
@ -177,12 +179,13 @@ export function sha256(str, encoding) {
* @param {Str} file [文件路径] * @param {Str} file [文件路径]
*/ */
export function sha256Sign(file) { export function sha256Sign(file) {
if (fs.accessSync(file, fs.constants.R_OK)) { try {
var buf = fs.readFileSync(file) let buf = fs.readFileSync(file)
return hash('sha256', buf) return hash('sha256', buf)
} } catch (e) {
return null return null
} }
}
export { export {
crypto, crypto,