Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Created May 24, 2019 20:51
Show Gist options
  • Save max-mapper/7b8722939a83dea1fb8374a43dcb322f to your computer and use it in GitHub Desktop.
Save max-mapper/7b8722939a83dea1fb8374a43dcb322f to your computer and use it in GitHub Desktop.
ed25519 private and public keys to pem
import { composePrivateKey, composePublicKey } from 'crypto-key-composer'
function privateToPem(privateKey) {
var decomposed = {
format: 'pkcs8-pem',
keyAlgorithm: { id: 'ed25519' },
keyData: {
seed: privateKey,
},
}
return composePrivateKey(decomposed)
}
function publicToPem(publicKey) {
var decomposed = {
format: 'spki-pem',
keyAlgorithm: { id: 'ed25519' },
keyData: {
bytes: publicKey,
},
}
return composePublicKey(decomposed)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment