* Getter for the current JSEncryptRSAKey object. If it doesn't exists a new object * will be created and returned * @param {callback} [cb] the callback to be called if we want the key to be generated * in an async fashion * @returns {JSEncryptRSAKey} the JSEncryptRSAKey object
(cb?: () => void)
| 203 | * @public |
| 204 | */ |
| 205 | public getKey(cb?: () => void) { |
| 206 | // Only create new if it does not exist. |
| 207 | if (!this.key) { |
| 208 | // Get a new private key. |
| 209 | this.key = new JSEncryptRSAKey(); |
| 210 | if (cb && {}.toString.call(cb) === "[object Function]") { |
| 211 | this.key.generateAsync( |
| 212 | this.default_key_size, |
| 213 | this.default_public_exponent, |
| 214 | cb, |
| 215 | ); |
| 216 | return; |
| 217 | } |
| 218 | // Generate the key. |
| 219 | this.key.generate(this.default_key_size, this.default_public_exponent); |
| 220 | } |
| 221 | return this.key; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Returns the pem encoded representation of the private key |
no test coverage detected