|
|
|
@ -1,20 +1,9 @@ |
|
|
|
|
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;
|
|
|
|
|
// let Base64 = require('js-base64').Base64
|
|
|
|
|
// import { JSEncrypt } from 'jsencrypt'
|
|
|
|
|
var keyStr = 'qDfajQ*v@W1mCruZ' |
|
|
|
|
// var dcodeIO = bcrypt.setRandomFallback
|
|
|
|
|
// var bcrypt = dcodeIO.bcrypt
|
|
|
|
|
|
|
|
|
|
export default { |
|
|
|
|
/** |
|
|
|
@ -32,14 +21,43 @@ export default { |
|
|
|
|
}, |
|
|
|
|
decrypt(word) { // 解密
|
|
|
|
|
var key = CryptoJS.enc.Utf8.parse(keyStr) |
|
|
|
|
// var srcs = CryptoJS.enc.Utf8.parse(word)
|
|
|
|
|
if(word) { |
|
|
|
|
word = word.replace(/[\r\n]/g,"") |
|
|
|
|
} |
|
|
|
|
var decrypt = CryptoJS.AES.decrypt(word, key, { |
|
|
|
|
mode: CryptoJS.mode.ECB, |
|
|
|
|
padding: CryptoJS.pad.Pkcs7 |
|
|
|
|
}) |
|
|
|
|
return CryptoJS.enc.Utf8.stringify(decrypt).toString() |
|
|
|
|
}, |
|
|
|
|
// decrypt (word) {
|
|
|
|
|
// var key = CryptoJS.enc.Utf8.parse(keyStr)
|
|
|
|
|
// var encryptedHexStr = CryptoJS.enc.Hex.parse(word);
|
|
|
|
|
// var srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
|
|
|
|
|
// var decrypt = CryptoJS.AES.decrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 })
|
|
|
|
|
// return decrypt.toString(CryptoJS.enc.Utf8).toString();
|
|
|
|
|
// },
|
|
|
|
|
// encrypt(data) {
|
|
|
|
|
// // 新建JSEncrypt对象
|
|
|
|
|
// let encryptor = new JSEncrypt();
|
|
|
|
|
// // 设置公钥
|
|
|
|
|
// encryptor.setPublicKey(keyStr);
|
|
|
|
|
// // 加密数据
|
|
|
|
|
// return encryptor.encrypt(data);
|
|
|
|
|
// },
|
|
|
|
|
// // 解密
|
|
|
|
|
// decrypt(data) {
|
|
|
|
|
// // 新建JSEncrypt对象
|
|
|
|
|
// let decrypt = new JSEncrypt();
|
|
|
|
|
// // 设置私钥
|
|
|
|
|
// decrypt.setPrivateKey(keyStr);
|
|
|
|
|
// // 解密数据
|
|
|
|
|
// return decrypt.decrypt(secretWord);
|
|
|
|
|
// },
|
|
|
|
|
md5Salt(str) { |
|
|
|
|
return Base64.encode(md5(str + 'Do&9hY%l8e')) |
|
|
|
|
console.log('hahahahaha',str, str + "Do&9hY%l8e", md5(str + 'Do&9hY%l8e')) |
|
|
|
|
return md5(str + 'Do&9hY%l8e') |
|
|
|
|
}, |
|
|
|
|
md5NoSalt(str) { |
|
|
|
|
return md5(str) |
|
|
|
@ -56,11 +74,6 @@ export default { |
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|