Skip to content
/ ts-sjcl Public

Stanford Javascript Crypto Library updated to ES6

Notifications You must be signed in to change notification settings

maxzz/ts-sjcl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sjcl-ts

Stanford Javascript Crypto Library updated to ES6.

Tiny 2.72kB AES-GCM library

Installation

pnpm add ts-sjcl

Usage

import sjcl from 'ts-sjcl'

const password = sjcl.codec.utf8String.toBits('PASSWORD')
const iv = sjcl.codec.utf8String.toBits('IV')

const cipher = new sjcl.cipher.aes(password)

export function encrypt(plaintext) {
  return sjcl.codec.base64.fromBits(
    sjcl.mode.gcm.encrypt(cipher, sjcl.codec.utf8String.toBits(plaintext), iv)
  )
}

export function decrypt(ciphertext) {
  return sjcl.codec.utf8String.fromBits(
    sjcl.mode.gcm.decrypt(cipher, sjcl.codec.base64.toBits(ciphertext), iv)
  )
}

console.log(encrypt('Hello World!'))
console.log(decrypt('0sFJ9r7c33z7gB4u1pD0xzuX48xaYVBGLj41UQ=='))

Documentation

https://bitwiseshiftleft.github.io/sjcl/doc

Credits, refs, links

About

Stanford Javascript Crypto Library updated to ES6

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published