Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ OR download from github and place in ./node_modules
### Usage



```js
var keygen = require('ssh-keygen');
var fs = require('fs');
Expand Down Expand Up @@ -69,6 +68,8 @@ The key's randomart image is:
* destroy, destroy the key files once they have been read, defaults false
* comment, the comment that should be embedded into the key, defaults empty
* password, the password for the key, defaults empty
* encryption, Supports all other encrytpions by default rsa
* size , the bit size for the encryption, by default the recommended size for the encryption specified

### Note

Expand Down
23 changes: 21 additions & 2 deletions src/ssh-keygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,30 @@ function ssh_keygen(location, opts, callback){

var pubLocation = location+'.pub';
if(!opts.comment) opts.comment = '';
if(!opts.encryption) opts.encryption='rsa';
if(!opts.password) opts.password = '';
if(!opts.size) opts.size = '2048';
if(!opts.size) {
switch(opts.encryption){
case 'rsa': opts.size = '2048';break;
case 'dsa': opts.size = '1024';break;
case 'ecdsa': opts.size = '256';break;
case 'ed25519': opts.size = '256';break;
default: opts.size='2048';opts.encryption='rsa';
}
}
else{
switch(opts.encryption){
case 'rsa': if (!(['1024','2048'].indexOf(opts.size)>=0)) opts.size = '2048';break;
case 'dsa': if (!(['1024'].indexOf(opts.size)>=0)) opts.size = '1024';break;
case 'ecdsa': if (!(['256','384','521'].indexOf(opts.size)>=0)) opts.size = '521'; break;
case 'ed25519':if (!(['256'].indexOf(opts.size)>=0)) opts.size = '256';break;
default: opts.size='2048'; opts.encryption='rsa';
}
}


var keygen = spawn(binPath(), [
'-t','rsa',
'-t', opts.encryption,
'-b', opts.size,
'-C', opts.comment,
'-N', opts.password,
Expand Down