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 🙏

© 2026 – Pkg Stats / Ryan Hefner

web-secure-encryption

v1.0.3

Published

A encryption library for ReactJS and React Native Web

Readme

WebEncryption Library Documentation

📚 Introduction

WebEncryption is a JavaScript/TypeScript library designed for cryptographic operations, including AES encryption, RSA encryption, ECDSA key pair generation, HMAC signature generation, and hashing. This library leverages the Web Crypto API to provide secure and performant encryption functionalities.


🚀 Installation

Using npm:

npm install web-secure-encryption

Using yarn:

yarn add web-secure-encryption

🛠️ Methods Overview

AES Encryption and Decryption

generateAESKey

Generates an AES-GCM encryption key.

generateAESKey(keySize: number = 256): Promise<string>
  • keySize: AES key size (128, 192, 256)
  • Returns: Base64-encoded AES Key.

encryptAES

Encrypts a string using AES-GCM.

encryptAES(data: string, keyBase64: string): Promise<string>
  • data: Plaintext to encrypt.
  • keyBase64: Base64-encoded AES key.
  • Returns: Base64-encoded IV + Ciphertext.

decryptAES

Decrypts a Base64-encoded ciphertext using AES-GCM.

decryptAES(encryptedData: string, keyBase64: string): Promise<string>
  • encryptedData: Base64-encoded ciphertext.
  • keyBase64: Base64-encoded AES key.
  • Returns: Decrypted plaintext.

Hashing

hashSHA256

Generates a SHA-256 hash.

hashSHA256(input: string): Promise<string>
  • input: String to hash.
  • Returns: Base64-encoded SHA-256 hash.

hashSHA512

Generates a SHA-512 hash.

hashSHA512(input: string): Promise<string>
  • input: String to hash.
  • Returns: Base64-encoded SHA-512 hash.

HMAC Signatures

generateHMACKey

Generates an HMAC key.

generateHMACKey(keySize: number): Promise<string>
  • keySize: Size of the key (256 or 512 bits).
  • Returns: Base64-encoded HMAC key.

hmacSHA256

Generates an HMAC-SHA256 signature.

hmacSHA256(data: string, key: string): Promise<string>
  • data: Data to sign.
  • key: Base64-encoded HMAC key.
  • Returns: Base64-encoded HMAC signature.

hmacSHA512

Generates an HMAC-SHA512 signature.

hmacSHA512(data: string, key: string): Promise<string>
  • data: Data to sign.
  • key: Base64-encoded HMAC key.
  • Returns: Base64-encoded HMAC signature.

RSA Encryption and Decryption

generateRSAKeyPair

Generates an RSA Key Pair.

generateRSAKeyPair(): Promise<Keypair>
  • Returns: Object containing Base64-encoded public and private keys.

encryptRSA

Encrypts data using an RSA public key.

encryptRSA(data: string, publicKeyBase64: string): Promise<string>
  • data: Data to encrypt.
  • publicKeyBase64: Base64-encoded RSA public key.
  • Returns: Base64-encoded encrypted data.

decryptRSA

Decrypts data using an RSA private key.

decryptRSA(data: string, privateKeyBase64: string): Promise<string>
  • data: Encrypted data.
  • privateKeyBase64: Base64-encoded RSA private key.
  • Returns: Decrypted plaintext.

importRSAPublicKey

Imports an RSA public key.

importRSAPublicKey(publicKeyBase64: string): Promise<CryptoKey>
  • publicKeyBase64: Base64-encoded RSA public key.
  • Returns: Imported RSA public key.

importRSAPrivateKey

Imports an RSA private key.

importRSAPrivateKey(privateKeyBase64: string): Promise<CryptoKey>
  • privateKeyBase64: Base64-encoded RSA private key.
  • Returns: Imported RSA private key.

ECDSA (Elliptic Curve Digital Signature Algorithm)

generateECDSAKeyPair

Generates an ECDSA Key Pair.

generateECDSAKeyPair(): Promise<Keypair>
  • Returns: Object containing Base64-encoded public and private keys.

getPublicECDSAKey

Extracts the public key from a private ECDSA key.

getPublicECDSAKey(privateKeyBase64: string): Promise<string>
  • privateKeyBase64: Base64-encoded private key.
  • Returns: Base64-encoded public key.

signDataECDSA

Signs data using an ECDSA private key.

signDataECDSA(data: string, privateKeyBase64: string): Promise<string>
  • data: Data to sign.
  • privateKeyBase64: Base64-encoded private key.
  • Returns: Base64-encoded signature.

verifySignatureECDSA

Verifies an ECDSA signature.

verifySignatureECDSA(data: string, signatureBase64: string, publicKeyBase64: string): Promise<boolean>
  • data: Original data.
  • signatureBase64: Base64-encoded signature.
  • publicKeyBase64: Base64-encoded public key.
  • Returns: true if the signature is valid.

Utilities

generateRandomString

Generates a random string of a specified length.

generateRandomString(length: number): string
  • length: Length of the random string.
  • Returns: Random string.

base64Encode

Encodes a string in Base64.

base64Encode(input: string): string
  • input: String to encode.
  • Returns: Base64-encoded string.

base64Decode

Decodes a Base64-encoded string.

base64Decode(input: string): string
  • input: Base64-encoded string.
  • Returns: Decoded string.

📝 License

MIT