0.0.15 • Published 1 month ago

@bicycle-codes/simple-aes v0.0.15

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

simple AES

tests module types semantic versioning license

Cryptography used by vanishing.page. Works in browsers and node.

This is generally useful as a dead simple way of working with symmetric keys in a browser or node.

Thanks to Fission, the original author for much of this code.

install

npm i -S @bicycle-codes/simple-aes

API

encryptMessage

Encrypt the given message object, and return an array of [ encryptedMessage, { key }], where key is a new AES key, encoded as base64url.

async function encryptMessage (
    msg:{ content:string }
):Promise<[{ content:string }, { key }]>

encrypt example

import { encryptMessage } from '@bicycle-codes/simple-aes'

const [encryptedMsg, { key }] = await encryptMessage({
    content: 'hello world'
})

console.log(encryptedMessage)
// =>  { content: '5eAcA6+jnBfbuCx8L...' }

decryptMessage

Decrypt the given message with the given key. Suitable for decrypting a message that was encrypted by this library. Key is an AES key, base64url encoded.

async function decryptMessage (
    msg:{ content:string },
    keyString:string  // <-- base64url
):Promise<{ content:string }>

decrypt example

import { test } from '@nichoth/tapzero'
import { decryptMessage } from '@bicycle-codes/simple-aes'

test('decrypt the message', async t => {
    const decrypted = await decryptMessage(message, key)
    t.equal(decrypted.content, 'hello world',
        'should decrypt to the right text')
})
0.0.14

1 month ago

0.0.15

1 month ago

0.0.13

3 months ago

0.0.12

3 months ago

0.0.11

3 months ago

0.0.9

3 months ago

0.0.8

3 months ago

0.0.7

3 months ago

0.0.6

3 months ago

0.0.5

3 months ago