JSEncrypt.d.ts 5.7 KB

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