format-hex.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. CryptoJS v3.1.2
  3. code.google.com/p/crypto-js
  4. (c) 2009-2013 by Jeff Mott. All rights reserved.
  5. code.google.com/p/crypto-js/wiki/License
  6. */
  7. (function (undefined) {
  8. // Shortcuts
  9. var C = CryptoJS;
  10. var C_lib = C.lib;
  11. var CipherParams = C_lib.CipherParams;
  12. var C_enc = C.enc;
  13. var Hex = C_enc.Hex;
  14. var C_format = C.format;
  15. var HexFormatter = C_format.Hex = {
  16. /**
  17. * Converts the ciphertext of a cipher params object to a hexadecimally encoded string.
  18. *
  19. * @param {CipherParams} cipherParams The cipher params object.
  20. *
  21. * @return {string} The hexadecimally encoded string.
  22. *
  23. * @static
  24. *
  25. * @example
  26. *
  27. * var hexString = CryptoJS.format.Hex.stringify(cipherParams);
  28. */
  29. stringify: function (cipherParams) {
  30. return cipherParams.ciphertext.toString(Hex);
  31. },
  32. /**
  33. * Converts a hexadecimally encoded ciphertext string to a cipher params object.
  34. *
  35. * @param {string} input The hexadecimally encoded string.
  36. *
  37. * @return {CipherParams} The cipher params object.
  38. *
  39. * @static
  40. *
  41. * @example
  42. *
  43. * var cipherParams = CryptoJS.format.Hex.parse(hexString);
  44. */
  45. parse: function (input) {
  46. var ciphertext = Hex.parse(input);
  47. return CipherParams.create({ ciphertext: ciphertext });
  48. }
  49. };
  50. }());