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",
"version": "3.2.1",
"version": "3.2.2",
"description": "原生crypto加密模块的二次封装,简化常用加密函数的使用",
"keywords": [
"md5",

View File

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