parent
1f1fe657f8
commit
9f5580edfa
|
@ -117,15 +117,14 @@ crypto.base64encode('hello world') //aGVsbG8gd29ybGQ=
|
|||
|
||||
|
||||
|
||||
### base64decode(str[, urlFriendly][, outEncode])
|
||||
### base64decode(str[, urlFriendly])
|
||||
- str `<String>`
|
||||
- urlFriendly `<Boolean>` 可选
|
||||
- outEncode `<String>` 可选,默认ascii, 如果之前的编码的字符串带有中文等字符,请设置为utf8等
|
||||
|
||||
> 与之对应的,便是这个base解码了。同样`urlFriendly`是指要解码的字符串之前是否采用了URL友好处理,默认否。
|
||||
> base64解码, 返回Buffer对象。同样`urlFriendly`是指要解码的字符串之前是否采用了URL友好处理,默认否。
|
||||
|
||||
```javascript
|
||||
crypto.base64decode('aGVsbG8gd29ybGQ=') //hello world
|
||||
crypto.base64decode('aGVsbG8gd29ybGQ=')// .toString('utf-8') === hello world
|
||||
|
||||
```
|
||||
|
||||
|
|
16
index.js
16
index.js
|
@ -211,10 +211,11 @@ module.exports = {
|
|||
* @param {bool} urlFriendly [是否对URL友好,默认否,是则会把+转成-,/转成_]
|
||||
*/
|
||||
base64encode(str, urlFriendly) {
|
||||
let buf
|
||||
if (!Buffer.isBuffer(str)) {
|
||||
str = Buffer.from(str + '')
|
||||
buf = Buffer.from(str + '')
|
||||
}
|
||||
let encode = str.toString('base64')
|
||||
let encode = buf.toString('base64')
|
||||
if (urlFriendly) {
|
||||
return encode
|
||||
.replace(/\+/g, '-')
|
||||
|
@ -225,10 +226,9 @@ module.exports = {
|
|||
},
|
||||
|
||||
/**
|
||||
* [base64decode base64解密]
|
||||
* [base64decode base64解密, 返回Buffer对象]
|
||||
* @param {Str} str [要解密的字符串]
|
||||
* @param {bool} urlFriendly [之前是否对结果采用了URL友好处理]
|
||||
* @param {Str/Buffer} encoding [编码,默认utf-8]
|
||||
*/
|
||||
base64decode(str, urlFriendly, encoding) {
|
||||
if (urlFriendly) {
|
||||
|
@ -238,12 +238,6 @@ module.exports = {
|
|||
.replace(/[^A-Za-z0-9\+\/]/g, '')
|
||||
}
|
||||
|
||||
let buff = Buffer.from(str, 'base64')
|
||||
|
||||
if (encoding === 'buffer') {
|
||||
return buff
|
||||
}
|
||||
|
||||
return buff.toString(encoding || 'ascii')
|
||||
return Buffer.from(str, 'base64')
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "crypto.js",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"description": "原生crypto加密模块的二次封装,简化常用加密函数的使用",
|
||||
"keywords": ["md5", "sha1", "base64", "fivejs", "crypto"],
|
||||
"author": "yutent <yutent@doui.cc>",
|
||||
|
|
Loading…
Reference in New Issue