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 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-aes-cbc

v3.1.1

Published

A simple wrapper for WebCrypto which uses the AES-CBC algorithm.

Downloads

236

Readme

simple_aes_cbc

This is a TypeScript module that provides a simple class for encryption and decryption functionality. It uses the AES-CBC-algorithm and it uses atob and btoa functions to perform base64 encoding/decoding.

Installation

deno

import { SimpleAesCbc } from "https://deno.land/x/simple_aes_cbc/mod.ts";

node

npm install simple-aes-cbc
bun install simple-aes-cbc
yarn install simple-aes-cbc

... etc

Usage

Here's an example of how to use this module:

deno

import { SimpleAesCbc } from "https://deno.land/x/simple_aes_cbc/mod.ts";

const stringCrypto = new SimpleAesCbc("1234567890123456", crypto.subtle);

const data = "hello my friend";

const encrypted = await stringCrypto.encryptString(data);

const decrypted = await stringCrypto.decryptString(encrypted);

console.log(decrypted); // "hello my friend"

node

import { webcrypto } from "node:crypto";
import { SimpleAesCbc } from "simple-aes-cbc";

const stringCrypto = new SimpleAesCbc("1234567890123456", webcrypto.subtle);

// ... same as above

API

new SimpleAesCbc(private_key: Uint8Array | string, subtle: SubtleCrypto, iv?: Uint8Array | string)

This is the constructor of the SimpleAesCbc class. It takes three arguments:

  • private_key, 16, 24 or 32 bytes
  • subtle. Which is used to encrypt and decrypt the data
  • optional iv, 16 bytes.

encrypt(data: BufferSource): Promise<ArrayBuffer>

This method encrypts the given data.

decrypt(data: BufferSource): Promise<ArrayBuffer>

This method decrypts the given data.

encryptString(data: string): Promise<string>

Encrypts the given string using the private key. The encrypted string returned from this function might not be human readable or used safely in a URL. If you want a human readable string that is safe to use, use encryptStringSafe instead.

decryptString(data: string): Promise<string>

Decrypts the given string using the private key. This function expects the string to be in the same format as the one returned from encryptString. If you want to decrypt a string that was encrypted using encryptStringSafe, use decryptStringSafe instead.

encryptStringToBase64(data: string): Promise<string>

Encrypts the given string to a base64 encoded string using the private key. The encrypted string returned from this function is human readable and safe to use in a URL.

decryptStringFromBase64(data: string): Promise<string>

Decrypts the given base64 encoded string using the private key. This function expects the string to be in the same format as the one returned from encryptStringToBase64.

License

This module is licensed under the MIT License.