Last active
September 11, 2015 19:53
-
-
Save max-mapper/3572c4d148feae15060f to your computer and use it in GitHub Desktop.
generate rsa keypair and format public key in openssh format in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// warning you probably want `ssh-keygen -t ed25519` for most use cases. this method lacks secure prng and uses weak rsa | |
var keypair = require('keypair') | |
var forge = require('node-forge') | |
// generates new keypair (slow) | |
var pair = keypair() | |
// creates intermediate forge key object | |
var publicKey = forge.pki.publicKeyFromPem(pair.public) | |
// formats in openssh format, e.g. compatible with authorized_keys file | |
var publicKeyOpenSSH = forge.ssh.publicKeyToOpenSSH(publicKey, '[email protected]') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment