💯 JWK to SSH in a lightweight, zero-dependency library.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
AJ ONeal 093c156ea6 v1.2.0: add support for OpenSSH private keys (EC and RSA) 5 years ago
bin v1.2.0: add support for OpenSSH private keys (EC and RSA) 5 years ago
fixtures v1.2.0: add support for OpenSSH private keys (EC and RSA) 5 years ago
lib v1.2.0: add support for OpenSSH private keys (EC and RSA) 5 years ago
README.md v1.2.0: add support for OpenSSH private keys (EC and RSA) 5 years ago
index.js v1.0.0: pack EC and RSA ssh public keys 5 years ago
package.json v1.2.0: add support for OpenSSH private keys (EC and RSA) 5 years ago
test.sh v1.2.0: add support for OpenSSH private keys (EC and RSA) 5 years ago

README.md

JWK to SSH (for node.js)

A minimal library to encode a JWK as an SSH public key (id_rsa.pub).

Works for RSA and ECDSA public keys.

Features

< 75 lines of code | < 0.7kb gzipped | 1.5kb minified | 2.1kb with comments

  • SSH Public Keys
  • OpenSSH Private Keys
  • RSA Keys
  • EC Keys
    • P-256 (prime256v1, secp256r1)
    • P-384 (secp384r1)
  • Browser Version

Note: the file size stats are for v1.0 which did not include private key packing. I plan to go back and update the stats, but just know that it grew a little over 2x.

Need JWK to SSH? PEM to SSH?

Try one of these:

Need Alternate SSH Private Keys?

This library supports OpenSSH private keys.

  • OpenSSH
  • Normal PKCS1 / SEC1 / PKCS8
    • Rasha.js
    • Eckles.js
  • Putty

Library Usage

You can also use it from JavaScript:

var fs = require('fs');
var jwktossh = require('jwk-to-ssh');

var jwk = JSON.parse(fs.readFileSync("./privkey.jwk.json"));
var pub = jwktossh.pack({
  jwk: jwk
, comment: 'root@localhost'
, public: true
});

console.info(pub);

CLI Usage

You can install jwk-to-ssh and use it from command line:

npm install -g jwk-to-ssh
jwk-to-ssh [keyfile] [comment] [public]
jwk-to-ssh pubkey.jwk.json
jwk-to-ssh privkey.jwk.json root@localhost
jwk-to-ssh privkey.jwk.json root@localhost public

jwk-to-ssh.js | MPL-2.0 | Terms of Use | Privacy Policy