format-hex.js 991 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import {
  2. CipherParams,
  3. } from './cipher-core.js';
  4. import {
  5. Hex,
  6. } from './core.js';
  7. export const HexFormatter = {
  8. /**
  9. * Converts the ciphertext of a cipher params object to a hexadecimally encoded string.
  10. *
  11. * @param {CipherParams} cipherParams The cipher params object.
  12. *
  13. * @return {string} The hexadecimally encoded string.
  14. *
  15. * @static
  16. *
  17. * @example
  18. *
  19. * var hexString = CryptoJS.format.Hex.stringify(cipherParams);
  20. */
  21. stringify(cipherParams) {
  22. return cipherParams.ciphertext.toString(Hex);
  23. },
  24. /**
  25. * Converts a hexadecimally encoded ciphertext string to a cipher params object.
  26. *
  27. * @param {string} input The hexadecimally encoded string.
  28. *
  29. * @return {CipherParams} The cipher params object.
  30. *
  31. * @static
  32. *
  33. * @example
  34. *
  35. * var cipherParams = CryptoJS.format.Hex.parse(hexString);
  36. */
  37. parse(input) {
  38. const ciphertext = Hex.parse(input);
  39. return CipherParams.create({ ciphertext });
  40. },
  41. };