crypto-es
Version:
A cryptography algorithms library compatible with ES6 and TypeScript
1 lines • 1.56 kB
Source Map (JSON)
{"version":3,"file":"format-hex.mjs","names":["HexFormatter: Format"],"sources":["../src/format-hex.ts"],"sourcesContent":["import {\n CipherParams,\n Format,\n} from './cipher-core';\nimport {\n Hex,\n} from './core';\n\n/**\n * Hex formatter for cipher params.\n * Converts cipher params to/from hexadecimal strings.\n */\nexport const HexFormatter: Format = {\n /**\n * Converts the ciphertext of a cipher params object to a hexadecimally encoded string.\n *\n * @param cipherParams - The cipher params object.\n * @returns The hexadecimally encoded string.\n *\n * @example\n * ```js\n * const hexString = CryptoJS.format.Hex.stringify(cipherParams);\n * ```\n */\n stringify(cipherParams: CipherParams): string {\n if (!cipherParams.ciphertext) {\n throw new Error('Ciphertext is required');\n }\n return cipherParams.ciphertext.toString(Hex);\n },\n\n /**\n * Converts a hexadecimally encoded ciphertext string to a cipher params object.\n *\n * @param input - The hexadecimally encoded string.\n * @returns The cipher params object.\n *\n * @example\n * ```js\n * const cipherParams = CryptoJS.format.Hex.parse(hexString);\n * ```\n */\n parse(input: string): CipherParams {\n const ciphertext = Hex.parse(input);\n return CipherParams.create({ ciphertext });\n },\n};"],"mappings":";;;;;;;;AAYA,MAAaA,eAAuB;CAYlC,UAAU,cAAoC;AAC5C,MAAI,CAAC,aAAa,WAChB,OAAM,IAAI,MAAM;AAElB,SAAO,aAAa,WAAW,SAAS;CACzC;CAaD,MAAM,OAA6B;EACjC,MAAM,aAAa,IAAI,MAAM;AAC7B,SAAO,aAAa,OAAO,EAAE,YAAY;CAC1C;CACF"}