weaver_encrypt.js
2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var encryptSeparator = "----weaversecurity----";
var __WEAVEREncrypt__ = (function () {
return (function () {
var AES_UUID = null;
var RSA_PUB = null;
return {
weaver_encrypt: function (value) {
if (!value && !AES_UUID) return value;
var key = AES_UUID;
var encodeKey = CryptoJS.enc.Utf8.parse(key);
value = CryptoJS.enc.Utf8.parse(value);
var encryptedStr = CryptoJS.AES.encrypt(value, encodeKey, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
}).toString();
return encodeURIComponent(encryptedStr)
},
getKey: function () {
var key = AES_UUID;
//对密钥进行RSA加密处理
var encrypt = new JSEncrypt();
encrypt.setPublicKey(RSA_PUB);
return encodeURIComponent(encrypt.encrypt(key) + "``RSA``");
},
initWEAVERCode: function (callback) {
if (RSA_PUB && AES_UUID) {
if (callback) {
callback();
}
} else {
var uuid = function () {
/**
* @return {string}
*/
function S4() {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4()).substr(0, 16);
}
AES_UUID = uuid();
jQuery.ajax({
url: "/rsa/weaver.rsa.GetRsaInfo?ts=" + new Date().getTime(),
type: "post",
dataType: "json",
success: function (data) {
RSA_PUB = data.rsa_pub;
if (callback) {
callback();
}
}
});
}
}
}
})();
})();
jQuery(document).ready(function () {
__WEAVEREncrypt__.initWEAVERCode();
});