You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.8 KiB
66 lines
1.8 KiB
import CryptoJS from 'crypto-js' |
|
import md5 from 'js-md5' |
|
// import dcodeIO from 'bcryptjs' |
|
require.config({ |
|
paths: { |
|
"bcrypt": "../node_modules/react-native-bcrypt/dist/bcrypt.js" |
|
} |
|
}); |
|
require(["bcrypt"], function(bcrypt) { |
|
console.log(bcrypt) |
|
}) |
|
let Base64 = require('js-base64').Base64 |
|
|
|
// var bcrypt = dcodeIO.bcrypt; |
|
var keyStr = 'qDfajQ*v@W1mCruZ' |
|
// var dcodeIO = bcrypt.setRandomFallback |
|
// var bcrypt = dcodeIO.bcrypt |
|
|
|
export default { |
|
/** |
|
* @param {*需要加密的字符串 注:对象转化为json字符串再加密} word |
|
* @param {*aes加密需要的key值,这个key值后端同学会告诉你} keyStr |
|
*/ |
|
encrypt(word) { // 加密 |
|
var key = CryptoJS.enc.Utf8.parse(keyStr) |
|
var srcs = CryptoJS.enc.Utf8.parse(word) |
|
var encrypted = CryptoJS.AES.encrypt(srcs, key, { |
|
mode: CryptoJS.mode.ECB, |
|
padding: CryptoJS.pad.Pkcs7 |
|
}) // 加密模式为ECB,补码方式为PKCS5Padding(也就是PKCS7) |
|
return encrypted.toString() |
|
}, |
|
decrypt(word) { // 解密 |
|
var key = CryptoJS.enc.Utf8.parse(keyStr) |
|
var decrypt = CryptoJS.AES.decrypt(word, key, { |
|
mode: CryptoJS.mode.ECB, |
|
padding: CryptoJS.pad.Pkcs7 |
|
}) |
|
return CryptoJS.enc.Utf8.stringify(decrypt).toString() |
|
}, |
|
md5Salt(str) { |
|
return Base64.encode(md5(str + 'Do&9hY%l8e')) |
|
}, |
|
md5NoSalt(str) { |
|
return md5(str) |
|
}, |
|
uuid() { // 获取uuid |
|
var s = [] |
|
var hexDigits = '0123456789abcdef' |
|
for (var i = 0; i < 36; i++) { |
|
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1) |
|
} |
|
s[14] = '4' |
|
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1) |
|
s[8] = s[13] = s[18] = s[23] = '-' |
|
|
|
var uuid = s.join('') |
|
return uuid |
|
}, |
|
bcrypt(str) { |
|
var salt = bcrypt.genSaltSync(10) // 定义密码加密的计算强度,默认10 |
|
var hash = bcrypt.hashSync(this.md5Salt(str), salt) // 把要加密的内容带进去,变量hash就是加密后的密码 |
|
return hash |
|
} |
|
|
|
}
|
|
|