CreateKey Method
Creates a new key.
Syntax
rsa.createKey([callback])
Callback
The 'callback' parameter specifies a function which will be called when the operation completes (or an error is encountered). If the 'callback' parameter is not specified, then the method will block and will not return until the operation completes (or an error is encountered).
The callback for this method is defined as:
function(err){ }
'err' is the error that occurred. If there was no error, then 'err' is 'null'.
'err' has 2 properties which hold detailed information:
err.code err.message
Remarks
This method creates a new public and private key.
When calling CreateKey the Key* properties are populated with a new private and public key.
RSA Keys
A RSA key is made up of a number of individual parameters.
The public key consists of the following parameters:
The class also includes the KeyPublicKey property which holds the PEM formatted public key for ease of use. This is helpful if you are in control of both sides of the encryption/signing and decryption/signature verification process. When sending the public key to a recipient note that not all implementations will support using the PEM formatted value in KeyPublicKey in which case the individual parameters must be sent.
The private key may be represented in one of two ways. Both are mathematically equivalent. Private key format 1:
Private key format 2 is simpler but has decreased performance when decrypting and signing. This format is: The class also include the KeyPrivateKey property which holds the PEM formatted private key for ease of use. This is helpful for storing the private key more easily.