Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@bicycle-codes/ephemeral-crypto

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bicycle-codes/ephemeral-crypto

In-browser cryptography

latest
Source
npmnpm
Version
0.0.5
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

ephemeral crypto

tests types module semantic versioning license

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

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

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

install

npm i -S @bicycle-codes/ephemeral-crypto

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/ephemeral-crypto'

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/ephemeral-crypto'

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

[!NOTE]
This uses forks of one-webcrypto and uint8arrays so that we own the entire dependency graph.

Keywords

cryptography

FAQs

Package last updated on 03 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts