From f6d301767eec24a8fb18dc89522aef8d7bf698f2 Mon Sep 17 00:00:00 2001 From: Navin Infant Raj Date: Sat, 24 Nov 2018 12:12:09 +0530 Subject: [PATCH] support encryption method --- README.md | 3 ++- src/ssh-keygen.js | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4d9ccef..e89c6b4 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,6 @@ OR download from github and place in ./node_modules ### Usage - ```js var keygen = require('ssh-keygen'); var fs = require('fs'); @@ -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 diff --git a/src/ssh-keygen.js b/src/ssh-keygen.js index 1704fdf..7b1158b 100644 --- a/src/ssh-keygen.js +++ b/src/ssh-keygen.js @@ -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,