JSEncrypt.d.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { JSEncryptRSAKey } from "./JSEncryptRSAKey";
  2. export interface IJSEncryptOptions {
  3. default_key_size?: string;
  4. default_public_exponent?: string;
  5. log?: boolean;
  6. }
  7. /**
  8. *
  9. * @param {Object} [options = {}] - An object to customize JSEncrypt behaviour
  10. * possible parameters are:
  11. * - default_key_size {number} default: 1024 the key size in bit
  12. * - default_public_exponent {string} default: '010001' the hexadecimal representation of the public exponent
  13. * - log {boolean} default: false whether log warn/error or not
  14. * @constructor
  15. */
  16. export declare class JSEncrypt {
  17. constructor(options: IJSEncryptOptions);
  18. private default_key_size;
  19. private default_public_exponent;
  20. private log;
  21. private key;
  22. static version: string;
  23. /**
  24. * Method to set the rsa key parameter (one method is enough to set both the public
  25. * and the private key, since the private key contains the public key paramenters)
  26. * Log a warning if logs are enabled
  27. * @param {Object|string} key the pem encoded string or an object (with or without header/footer)
  28. * @public
  29. */
  30. setKey(key: string): void;
  31. /**
  32. * Proxy method for setKey, for api compatibility
  33. * @see setKey
  34. * @public
  35. */
  36. setPrivateKey(privkey: string): void;
  37. /**
  38. * Proxy method for setKey, for api compatibility
  39. * @see setKey
  40. * @public
  41. */
  42. setPublicKey(pubkey: string): void;
  43. /**
  44. * Proxy method for RSAKey object's decrypt, decrypt the string using the private
  45. * components of the rsa key object. Note that if the object was not set will be created
  46. * on the fly (by the getKey method) using the parameters passed in the JSEncrypt constructor
  47. * @param {string} str base64 encoded crypted string to decrypt
  48. * @return {string} the decrypted string
  49. * @public
  50. */
  51. decrypt(str: string): string | false;
  52. /**
  53. * Proxy method for RSAKey object's encrypt, encrypt the string using the public
  54. * components of the rsa key object. Note that if the object was not set will be created
  55. * on the fly (by the getKey method) using the parameters passed in the JSEncrypt constructor
  56. * @param {string} str the string to encrypt
  57. * @return {string} the encrypted string encoded in base64
  58. * @public
  59. */
  60. encrypt(str: string): string | false;
  61. /**
  62. * Proxy method for RSAKey object's sign.
  63. * @param {string} str the string to sign
  64. * @param {function} digestMethod hash method
  65. * @param {string} digestName the name of the hash algorithm
  66. * @return {string} the signature encoded in base64
  67. * @public
  68. */
  69. sign(str: string, digestMethod: (str: string) => string, digestName: string): string | false;
  70. /**
  71. * Proxy method for RSAKey object's verify.
  72. * @param {string} str the string to verify
  73. * @param {string} signature the signature encoded in base64 to compare the string to
  74. * @param {function} digestMethod hash method
  75. * @return {boolean} whether the data and signature match
  76. * @public
  77. */
  78. verify(str: string, signature: string, digestMethod: (str: string) => string): boolean;
  79. /**
  80. * Getter for the current JSEncryptRSAKey object. If it doesn't exists a new object
  81. * will be created and returned
  82. * @param {callback} [cb] the callback to be called if we want the key to be generated
  83. * in an async fashion
  84. * @returns {JSEncryptRSAKey} the JSEncryptRSAKey object
  85. * @public
  86. */
  87. getKey(cb?: () => void): JSEncryptRSAKey;
  88. /**
  89. * Returns the pem encoded representation of the private key
  90. * If the key doesn't exists a new key will be created
  91. * @returns {string} pem encoded representation of the private key WITH header and footer
  92. * @public
  93. */
  94. getPrivateKey(): string;
  95. /**
  96. * Returns the pem encoded representation of the private key
  97. * If the key doesn't exists a new key will be created
  98. * @returns {string} pem encoded representation of the private key WITHOUT header and footer
  99. * @public
  100. */
  101. getPrivateKeyB64(): string;
  102. /**
  103. * Returns the pem encoded representation of the public key
  104. * If the key doesn't exists a new key will be created
  105. * @returns {string} pem encoded representation of the public key WITH header and footer
  106. * @public
  107. */
  108. getPublicKey(): string;
  109. /**
  110. * Returns the pem encoded representation of the public key
  111. * If the key doesn't exists a new key will be created
  112. * @returns {string} pem encoded representation of the public key WITHOUT header and footer
  113. * @public
  114. */
  115. getPublicKeyB64(): string;
  116. }