(data)
| 228 | }; |
| 229 | |
| 230 | createEncryptedBody(data) { |
| 231 | const key2 = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANMGZPlLobHYWoZyMvHD0a6emIjEmtf5Z6Q++VIBRulxsUfYvcczjB0fMVvAnd1douKmOX4G690q9NZ6Q7z/TV8CAwEAAQ=="; |
| 232 | const publicKeyPem = '-----BEGIN PUBLIC KEY-----\n' + |
| 233 | key2 + |
| 234 | '-----END PUBLIC KEY-----'; |
| 235 | |
| 236 | global["window"] = {} |
| 237 | const jsencrypt = require("jsencrypt") |
| 238 | const crypt = new jsencrypt() |
| 239 | crypt.setKey(publicKeyPem) |
| 240 | const n = this.randomStr(48, 16); |
| 241 | const encrypted = crypt.encrypt(n) |
| 242 | const enBody = CryptoJS.enc.Utf8.parse(data); |
| 243 | const enResult = CryptoJS.AES.encrypt(enBody, CryptoJS.enc.Utf8.parse(n.substr(10, 16)), { |
| 244 | iv: CryptoJS.enc.Utf8.parse(n.substr(20, 16)), |
| 245 | mode: CryptoJS.mode.CBC, |
| 246 | padding: CryptoJS.pad.Pkcs7, |
| 247 | }); |
| 248 | //console.log(encrypted); |
| 249 | //console.log(hexToBase64(encrypted)); |
| 250 | const newBody = { |
| 251 | data: encrypted + "" + enResult.ciphertext.toString().toUpperCase(), |
| 252 | }; |
| 253 | newBody.sign = this.calculateSign(newBody); |
| 254 | return { enData: newBody, n }; |
| 255 | function hexToBase64(hexString) { |
| 256 | const buffer = Buffer.from(hexString, 'hex'); |
| 257 | const base64String = buffer.toString('base64'); |
| 258 | return base64String; |
| 259 | } |
| 260 | } |
| 261 | randomStr(length, charset) { var tmp1, tmp2, data = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""), result = []; if (((charset = charset || data["length"]), length)) for (tmp1 = 0; tmp1 < length; tmp1++)result[tmp1] = data[0 | (Math.random() * charset)]; else for (result[8] = result[13] = result[18] = result[23] = "-", result[14] = "4", tmp1 = 0; tmp1 < 36; tmp1++)result[tmp1] || ((tmp2 = 0 | (16 * Math["random"]())), (result[tmp1] = data[19 === tmp1 ? (3 & tmp2) | 8 : tmp2])); return result["join"]("") } |
| 262 | decryptResponseBody(result, n) { |
| 263 | try { |
nothing calls this directly
no test coverage detected