@sentinel-one/decrypt-ssh-private

Decrypts ssh keys in the browser

Usage no npm install needed!

<script type="module">
  import sentinelOneDecryptSshPrivate from 'https://cdn.skypack.dev/@sentinel-one/decrypt-ssh-private';
</script>

README

decrypt-ssh-private

npm version License Node.js CI

A TS library that decrypts ssh keys in the browser.

Based on the nodejs node-sshpk and uses forge where possible.

Credit:

The authors of node-sshpk.

Special thanks to Ido Kotler (Sentinelone Innovative security researcher) for technical guidance and help in implementation 💣.

API:

import { decryptPrivateSSHKey } from '../lib/main';
import { ErrorClassification, ResultT } from '../lib/error-classifier';

const result: ResultT<ErrorClassification, string> = decryptPrivateSSHKey(encryptedSSHKey, { passphrase: '123456' });
result
  .ok((output: string) => {
    console.log(output);
    return result;
  })
  .err((err: ErrorClassification) => {
    // do something with the classified error
    console.log(err);
    return result;
  });

Util functions

  • isValidSSHKey(pem: string): boolean // Checks that a given PEM format is valid or not
if (isValidSSHKey('invalid key')) {
  // do sothing
};

To see it decrypts in the browser just build and serve the example:

esbuild-browser && npx http-server