npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@vf.js/pki

v1.1.1

Published

这是一个构建与pki.js之上的,用于处理公钥,私钥,证书,签名等基础设施的简单工具包。

Downloads

11

Readme

@vf.js/pki

说明

这是一个构建与pki.js之上的,用于处理公钥,私钥,证书,签名等基础设施的简单工具包。

  1. 提供密钥创建服务
  2. 提供证书创建服务 CSR 请求

安装

npm install @vf.js/pki

示例


import {
    generateKeypairPem,
    pemToPrivateKey,
    pemToPublicKey,
    certificationRequest,
    utf8tob64
} from "@vf.js/pki"

// 创建Pem格式的密钥对
const keypairPem = generateKeypairPem({ "alg": 'EC', "curve": "secp256r1" })

console.log(keypairPem.privateKeyPem)
console.log(keypairPem.publicKeyPem)

// 获取原生的密钥信息
const privateKey = await pemToPrivateKey(keypairPem.privateKeyPem);
const publicKey = await pemToPublicKey(keypairPem.publicKeyPem);

// 创建CSR证书请求
const csr = await certificationRequest(privateKey,publicKey,[
        {
            name: 'commonName',
            value: 'www.example.com'
        }, 
        {
            name: 'countryName',
            value: 'China'
        },
        {
            name: 'stateOrProvinceName',
            value: 'BeiJing'
        },
        {
            name: 'localityName',
            value: 'BeiJing'
        },
        {
            name: 'organizationName',
            value: 'Huawei'
        }, 
        {
            name: 'organizationalUnitName',
            value: 'client'
        },
])

console.log(csr.csrPem)

API

import { xxxxx } from "@vf.js/pki"

创建密钥对

const keypairPem = await generateKeypairPem({ "alg": 'EC', "curve": "secp256r1" })

console.log(keypairPem.privateKeyPem)
console.log(keypairPem.publicKeyPem)

默认加密类型

DefaultAlgorithm = 
{
    name: "ECDSA", // ✅ 正确的算法名称
    hash: "SHA-256", // ECDSA 必须指定哈希算法,比如 SHA-256
    namedCurve: "P-256", // 指定椭圆曲线,比如 P-256, P-384, P-521
};

从PEM证书获取公钥PEM

import { certToPublicPem } from "@vf.js/pki"

const pubPem = await certToPublicPem(certStrPem)

pem转换ArrayBuffer


await pemToArrayBuffer(pemStr);

ArrayBuffer转换pem

const pem = await arrayBufferToPem(signature,'CERTIFICATE REQUEST');

pem转换为ASN1格式

await pemToASN1(pemStr)

pem转换为私钥的原生模式

await pemToPrivateKey(pem: string, keyUsages?: KeyUsage[], keyFormat?: "pkcs8" | "raw")

pem转换为公钥的原生模式

await pemToPublicKey(publicKeyPem)

创建证书请求

查看示例

certificationRequest

获取原生Crypto

getCrypto

base64转utf8

b64toutf8

utf8转base64

utf8tob64