JSEncryptRSAKey.d.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import { RSAKey } from "./lib/jsbn/rsa";
  2. /**
  3. * Create a new JSEncryptRSAKey that extends Tom Wu's RSA key object.
  4. * This object is just a decorator for parsing the key parameter
  5. * @param {string|Object} key - The key in string format, or an object containing
  6. * the parameters needed to build a RSAKey object.
  7. * @constructor
  8. */
  9. export declare class JSEncryptRSAKey extends RSAKey {
  10. constructor(key?: string);
  11. /**
  12. * Method to parse a pem encoded string containing both a public or private key.
  13. * The method will translate the pem encoded string in a der encoded string and
  14. * will parse private key and public key parameters. This method accepts public key
  15. * in the rsaencryption pkcs #1 format (oid: 1.2.840.113549.1.1.1).
  16. *
  17. * @todo Check how many rsa formats use the same format of pkcs #1.
  18. *
  19. * The format is defined as:
  20. * PublicKeyInfo ::= SEQUENCE {
  21. * algorithm AlgorithmIdentifier,
  22. * PublicKey BIT STRING
  23. * }
  24. * Where AlgorithmIdentifier is:
  25. * AlgorithmIdentifier ::= SEQUENCE {
  26. * algorithm OBJECT IDENTIFIER, the OID of the enc algorithm
  27. * parameters ANY DEFINED BY algorithm OPTIONAL (NULL for PKCS #1)
  28. * }
  29. * and PublicKey is a SEQUENCE encapsulated in a BIT STRING
  30. * RSAPublicKey ::= SEQUENCE {
  31. * modulus INTEGER, -- n
  32. * publicExponent INTEGER -- e
  33. * }
  34. * it's possible to examine the structure of the keys obtained from openssl using
  35. * an asn.1 dumper as the one used here to parse the components: http://lapo.it/asn1js/
  36. * @argument {string} pem the pem encoded string, can include the BEGIN/END header/footer
  37. * @private
  38. */
  39. parseKey(pem: string): boolean;
  40. /**
  41. * Translate rsa parameters in a hex encoded string representing the rsa key.
  42. *
  43. * The translation follow the ASN.1 notation :
  44. * RSAPrivateKey ::= SEQUENCE {
  45. * version Version,
  46. * modulus INTEGER, -- n
  47. * publicExponent INTEGER, -- e
  48. * privateExponent INTEGER, -- d
  49. * prime1 INTEGER, -- p
  50. * prime2 INTEGER, -- q
  51. * exponent1 INTEGER, -- d mod (p1)
  52. * exponent2 INTEGER, -- d mod (q-1)
  53. * coefficient INTEGER, -- (inverse of q) mod p
  54. * }
  55. * @returns {string} DER Encoded String representing the rsa private key
  56. * @private
  57. */
  58. getPrivateBaseKey(): string;
  59. /**
  60. * base64 (pem) encoded version of the DER encoded representation
  61. * @returns {string} pem encoded representation without header and footer
  62. * @public
  63. */
  64. getPrivateBaseKeyB64(): string;
  65. /**
  66. * Translate rsa parameters in a hex encoded string representing the rsa public key.
  67. * The representation follow the ASN.1 notation :
  68. * PublicKeyInfo ::= SEQUENCE {
  69. * algorithm AlgorithmIdentifier,
  70. * PublicKey BIT STRING
  71. * }
  72. * Where AlgorithmIdentifier is:
  73. * AlgorithmIdentifier ::= SEQUENCE {
  74. * algorithm OBJECT IDENTIFIER, the OID of the enc algorithm
  75. * parameters ANY DEFINED BY algorithm OPTIONAL (NULL for PKCS #1)
  76. * }
  77. * and PublicKey is a SEQUENCE encapsulated in a BIT STRING
  78. * RSAPublicKey ::= SEQUENCE {
  79. * modulus INTEGER, -- n
  80. * publicExponent INTEGER -- e
  81. * }
  82. * @returns {string} DER Encoded String representing the rsa public key
  83. * @private
  84. */
  85. getPublicBaseKey(): string;
  86. /**
  87. * base64 (pem) encoded version of the DER encoded representation
  88. * @returns {string} pem encoded representation without header and footer
  89. * @public
  90. */
  91. getPublicBaseKeyB64(): string;
  92. /**
  93. * wrap the string in block of width chars. The default value for rsa keys is 64
  94. * characters.
  95. * @param {string} str the pem encoded string without header and footer
  96. * @param {Number} [width=64] - the length the string has to be wrapped at
  97. * @returns {string}
  98. * @private
  99. */
  100. static wordwrap(str: string, width?: number): string;
  101. /**
  102. * Retrieve the pem encoded private key
  103. * @returns {string} the pem encoded private key with header/footer
  104. * @public
  105. */
  106. getPrivateKey(): string;
  107. /**
  108. * Retrieve the pem encoded public key
  109. * @returns {string} the pem encoded public key with header/footer
  110. * @public
  111. */
  112. getPublicKey(): string;
  113. /**
  114. * Check if the object contains the necessary parameters to populate the rsa modulus
  115. * and public exponent parameters.
  116. * @param {Object} [obj={}] - An object that may contain the two public key
  117. * parameters
  118. * @returns {boolean} true if the object contains both the modulus and the public exponent
  119. * properties (n and e)
  120. * @todo check for types of n and e. N should be a parseable bigInt object, E should
  121. * be a parseable integer number
  122. * @private
  123. */
  124. static hasPublicKeyProperty(obj: object): boolean;
  125. /**
  126. * Check if the object contains ALL the parameters of an RSA key.
  127. * @param {Object} [obj={}] - An object that may contain nine rsa key
  128. * parameters
  129. * @returns {boolean} true if the object contains all the parameters needed
  130. * @todo check for types of the parameters all the parameters but the public exponent
  131. * should be parseable bigint objects, the public exponent should be a parseable integer number
  132. * @private
  133. */
  134. static hasPrivateKeyProperty(obj: object): boolean;
  135. /**
  136. * Parse the properties of obj in the current rsa object. Obj should AT LEAST
  137. * include the modulus and public exponent (n, e) parameters.
  138. * @param {Object} obj - the object containing rsa parameters
  139. * @private
  140. */
  141. parsePropertiesFrom(obj: any): void;
  142. }