1/** 2 * AES JSON formatter for CryptoJS 3 * Allows encryption/decryption with IV and Salt in JSON format. 4 * Works in browsers with CryptoJS included globally. 5 */ 6 7var CryptoJSAesJson = { 8 /** 9 * Stringify CipherParams to JSON string 10 * @param {CipherParams} cipherParams 11 * @returns {string} 12 */ 13 stringify: function (cipherParams) { 14 var jsonObj = { 15 ct: cipherParams.ciphertext.toString(CryptoJS.enc.Base64) 16 }; 17 if (cipherParams.iv) { 18 jsonObj.iv = cipherParams.iv.toString(); 19 } 20 if (cipherParams.salt) { 21 jsonObj.s = cipherParams.salt.toString(); 22 } 23 return JSON.stringify(jsonObj).replace(/\s/g, ''); 24 }, 25 26 /** 27 * Parse JSON string to CipherParams 28 * @param {string} jsonStr 29 * @returns {CipherParams} 30 */ 31 parse: function (jsonStr) { 32 var jsonObj = JSON.parse(jsonStr); 33 var cipherParams = CryptoJS.lib.CipherParams.create({ 34 ciphertext: CryptoJS.enc.Base64.parse(jsonObj.ct) 35 }); 36 if (jsonObj.iv) { 37 cipherParams.iv = CryptoJS.enc.Hex.parse(jsonObj.iv); 38 } 39 if (jsonObj.s) { 40 cipherParams.salt = CryptoJS.enc.Hex.parse(jsonObj.s); 41 } 42 return cipherParams; 43 } 44};
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.