UNPKG

1.82 kBJavaScriptView Raw
1;(function (root, factory, undef) {
2 if (typeof exports === "object") {
3 // CommonJS
4 module.exports = exports = factory(require("./core"), require("./cipher-core"));
5 }
6 else if (typeof define === "function" && define.amd) {
7 // AMD
8 define(["./core", "./cipher-core"], factory);
9 }
10 else {
11 // Global (browser)
12 factory(root.CryptoJS);
13 }
14}(this, function (CryptoJS) {
15
16 (function (undefined) {
17 // Shortcuts
18 var C = CryptoJS;
19 var C_lib = C.lib;
20 var CipherParams = C_lib.CipherParams;
21 var C_enc = C.enc;
22 var Hex = C_enc.Hex;
23 var C_format = C.format;
24
25 var HexFormatter = C_format.Hex = {
26 /**
27 * Converts the ciphertext of a cipher params object to a hexadecimally encoded string.
28 *
29 * @param {CipherParams} cipherParams The cipher params object.
30 *
31 * @return {string} The hexadecimally encoded string.
32 *
33 * @static
34 *
35 * @example
36 *
37 * var hexString = CryptoJS.format.Hex.stringify(cipherParams);
38 */
39 stringify: function (cipherParams) {
40 return cipherParams.ciphertext.toString(Hex);
41 },
42
43 /**
44 * Converts a hexadecimally encoded ciphertext string to a cipher params object.
45 *
46 * @param {string} input The hexadecimally encoded string.
47 *
48 * @return {CipherParams} The cipher params object.
49 *
50 * @static
51 *
52 * @example
53 *
54 * var cipherParams = CryptoJS.format.Hex.parse(hexString);
55 */
56 parse: function (input) {
57 var ciphertext = Hex.parse(input);
58 return CipherParams.create({ ciphertext: ciphertext });
59 }
60 };
61 }());
62
63
64 return CryptoJS.format.Hex;
65
66}));
\No newline at end of file