Skip to content
/ age.ts Public
forked from FiloSottile/typage

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

License

Notifications You must be signed in to change notification settings

lgarron/age.ts

 
 

Repository files navigation

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 98.2%
  • JavaScript 1.8%