lgarron / age.ts

A TypeScript implementation of the age file encryption format, based on libsodium.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The age logo, an wireframe of St. Peters dome in Rome, with the text: age, file encryption

age-encryption is a TypeScript implementation of the age file encryption format.

All low-level cryptographic operations are implemented with libsodium.js.

⚠️ This project is experimental. The author has near-zero JavaScript experience and help is very welcome. ⚠️

Installation

npm install age-encryption

Usage

import age from "age-encryption"

// Initialize the library (calls sodium.ready).

const { Encrypter, Decrypter, generateIdentity, identityToRecipient } = await age()

// Encrypt and decrypt a file with a new recipient / identity pair.

const identity = generateIdentity()
const recipient = identityToRecipient(identity)
console.log(identity)
console.log(recipient)

const e = new Encrypter()
e.addRecipient(recipient)
const ciphertext = e.encrypt("Hello, age!")

const d = new Decrypter()
d.addIdentity(identity)
const out = d.decrypt(ciphertext, "text")
console.log(out)

// Encrypt and decrypt a file with a passphrase.

const e = new Encrypter()
e.setPassphrase("burst-swarm-slender-curve-ability-various-crystal-moon-affair-three")
const ciphertext = e.encrypt("Hello, age!")

const d = new Decrypter()
d.addPassphrase("burst-swarm-slender-curve-ability-various-crystal-moon-affair-three")
const out = d.decrypt(ciphertext, "text")
console.log(out)

About

A TypeScript implementation of the age file encryption format, based on libsodium.

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:TypeScript 98.2%Language:JavaScript 1.8%