parent
e5aefc407d
commit
15ebc01f93
|
@ -117,9 +117,10 @@ crypto.base64encode('hello world') //aGVsbG8gd29ybGQ=
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### base64decode(str[, urlFriendly])
|
### base64decode(str[, urlFriendly][, outEncode])
|
||||||
- str `<String>`
|
- str `<String>`
|
||||||
- urlFriendly `<Boolean>` 可选
|
- urlFriendly `<Boolean>` 可选
|
||||||
|
- outEncode `<String>` 可选,默认ascii, 如果之前的编码的字符串带有中文等字符,请设置为utf8等
|
||||||
|
|
||||||
> 与之对应的,便是这个base解码了。同样`urlFriendly`是指要解码的字符串之前是否采用了URL友好处理,默认否。
|
> 与之对应的,便是这个base解码了。同样`urlFriendly`是指要解码的字符串之前是否采用了URL友好处理,默认否。
|
||||||
|
|
||||||
|
|
13
index.js
13
index.js
|
@ -188,13 +188,11 @@ module.exports = {
|
||||||
}
|
}
|
||||||
let encode = str.toString('base64')
|
let encode = str.toString('base64')
|
||||||
if (urlFriendly) {
|
if (urlFriendly) {
|
||||||
encode = encode
|
return encode
|
||||||
.replace(/[+\/]/g, m => {
|
.replace(/\+/g, '-')
|
||||||
return m === '+' ? '-' : '_'
|
.replace(/\//g, '_')
|
||||||
})
|
|
||||||
.replace(/=/g, '')
|
.replace(/=/g, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
return encode
|
return encode
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -207,9 +205,8 @@ module.exports = {
|
||||||
base64decode(str, urlFriendly, encoding) {
|
base64decode(str, urlFriendly, encoding) {
|
||||||
if (urlFriendly) {
|
if (urlFriendly) {
|
||||||
str = str
|
str = str
|
||||||
.replace(/[-_]/g, m => {
|
.replace(/-/g, '+')
|
||||||
return m === '-' ? '+' : '/'
|
.replace(/_/g, '/')
|
||||||
})
|
|
||||||
.replace(/[^A-Za-z0-9\+\/]/g, '')
|
.replace(/[^A-Za-z0-9\+\/]/g, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "crypto.js",
|
"name": "crypto.js",
|
||||||
"version": "1.1.3",
|
"version": "1.1.4",
|
||||||
"description": "原生crypto加密模块的二次封装,简化常用加密函数的使用",
|
"description": "原生crypto加密模块的二次封装,简化常用加密函数的使用",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"md5",
|
"md5",
|
||||||
|
|
Loading…
Reference in New Issue