1/** 2 * AES JSON formatter for CryptoJS 3 * @link https://github.com/brainfoolong/cryptojs-aes-php 4 * @version 2.1.1 5 */ 6 7var CryptoJSAesJson = { 8 /** 9 * Encrypt any value 10 * @param {*} value 11 * @param {string} password 12 * @return {string} 13 */ 14 'encrypt': function (value, password) { 15 return CryptoJS.AES.encrypt(JSON.stringify(value), password, { format: CryptoJSAesJson }).toString() 16 }, 17 /** 18 * Decrypt a previously encrypted value 19 * @param {string} jsonStr 20 * @param {string} password 21 * @return {*} 22 */ 23 'decrypt': function (jsonStr, password) { 24 return JSON.parse(CryptoJS.AES.decrypt(jsonStr, password, { format: CryptoJSAesJson }).toString(CryptoJS.enc.Utf8)) 25 }, 26 /** 27 * Stringify cryptojs data 28 * @param {Object} cipherParams 29 * @return {string} 30 */ 31 'stringify': function (cipherParams) { 32 var j = { ct: cipherParams.ciphertext.toString(CryptoJS.enc.Base64) } 33 if (cipherParams.iv) j.iv = cipherParams.iv.toString() 34 if (cipherParams.salt) j.s = cipherParams.salt.toString() 35 return JSON.stringify(j).replace(/\s/g, '') 36 }, 37 /** 38 * Parse cryptojs data 39 * @param {string} jsonStr 40 * @return {*} 41 */ 42 'parse': function (jsonStr) { 43 var j = JSON.parse(jsonStr) 44 var cipherParams = CryptoJS.lib.CipherParams.create({ ciphertext: CryptoJS.enc.Base64.parse(j.ct) }) 45 if (j.iv) cipherParams.iv = CryptoJS.enc.Hex.parse(j.iv) 46 if (j.s) cipherParams.salt = CryptoJS.enc.Hex.parse(j.s) 47 return cipherParams 48 } 49}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.