
Product
Unify Your Security Stack with Socket Basics
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.
@cef-ebsi/key-encoder
Advanced tools
Library for encoding ECDSA private keys to PEM, DER and raw hex formats
This library is a fork of https://www.npmjs.com/package/key-encoder.
npm install @cef-ebsi/key-encoder
To get started, first define your key encoder and raw private/public keys.
import { KeyEncoder } from "@cef-ebsi/key-encoder";
const keyEncoder = new KeyEncoder("secp256k1");
As shown above, there is built in support for SECP256k1 (the curve Bitcoin uses), but you can pass in your own curve parameters for any curve you'd like.
const encoderOptions = {
curveParameters: [1, 3, 132, 0, 10],
privatePEMOptions: { label: "EC PRIVATE KEY" },
publicPEMOptions: { label: "PUBLIC KEY" },
curve: "secp256k1",
};
const keyEncoder = new KeyEncoder(encoderOptions);
const rawPrivateKey =
"844055cca13efd78ce79a4c3a4c5aba5db0ebeb7ae9d56906c03d333c5668d5b";
const rawPublicKey =
"04147b79e9e1dd3324ceea115ff4037b6c877c73777131418bfb2b713effd0f502327b923861581bd5535eeae006765269f404f5f5c52214e9721b04aa7d040a75";
Encode to and from raw, PEM (encode to 'pkcs8' and 'pkcs1'), and DER formats.
const pemPrivateKey = keyEncoder.encodePrivate(
rawPrivateKey,
"raw",
"pem",
"pkcs8",
); //default is 'pkcs1'
Example output:
-----BEGIN PRIVATE KEY-----
MIGNAgEAMBAGByqGSM49AgEGBSuBBAAKBHYwdAIBAQQghEBVzKE+/XjOeaTDpMWr
pdsOvreunVaQbAPTM8VmjVugBwYFK4EEAAqhRANCAAQUe3np4d0zJM7qEV/0A3ts
h3xzd3ExQYv7K3E+/9D1AjJ7kjhhWBvVU17q4AZ2Umn0BPX1xSIU6XIbBKp9BAp1
-----END PRIVATE KEY-----
const derPrivateKey = keyEncoder.encodePrivate(rawPrivateKey, "raw", "der");
Example output:
30740201010420844055cca13efd78ce79a4c3a4c5aba5db0ebeb7ae9d56906c03d333c5668d5ba00706052b8104000aa14403420004147b79e9e1dd3324ceea115ff4037b6c877c73777131418bfb2b713effd0f502327b923861581bd5535eeae006765269f404f5f5c52214e9721b04aa7d040a75
Encode to and from raw, PEM, and DER formats.
const pemPublicKey = keyEncoder.encodePublic(rawPublicKey, "raw", "pem");
Example output:
-----BEGIN PUBLIC KEY-----
MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEFHt56eHdMyTO6hFf9AN7bId8c3dxMUGL
+ytxPv/Q9QIye5I4YVgb1VNe6uAGdlJp9AT19cUiFOlyGwSqfQQKdQ==
-----END PUBLIC KEY-----
const derPublicKey = keyEncoder.encodePublic(rawPublicKey, "raw", "der");
Example output:
3056301006072a8648ce3d020106052b8104000a03420004147b79e9e1dd3324ceea115ff4037b6c877c73777131418bfb2b713effd0f502327b923861581bd5535eeae006765269f404f5f5c52214e9721b04aa7d040a75
Copyright (C) 2025 European Union
This program is free software: you can redistribute it and/or modify it under the terms of the EUROPEAN UNION PUBLIC LICENCE v. 1.2 as published by the European Union.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the EUROPEAN UNION PUBLIC LICENCE v. 1.2 for further details.
You should have received a copy of the EUROPEAN UNION PUBLIC LICENCE v. 1.2. along with this program. If not, see https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12.
FAQs
Library for encoding ECDSA private keys to PEM, DER and raw hex formats
The npm package @cef-ebsi/key-encoder receives a total of 170 weekly downloads. As such, @cef-ebsi/key-encoder popularity was classified as not popular.
We found that @cef-ebsi/key-encoder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.
Product
Socket is launching experimental protection for the Hugging Face ecosystem, scanning for malware and malicious payload injections inside model files to prevent silent AI supply chain attacks.
Research
/Security News
The Socket Threat Research Team uncovered a coordinated campaign that floods the Chrome Web Store with 131 rebranded clones of a WhatsApp Web automation extension to spam Brazilian users.