A very simple-to-use cryptosystem, designed to make security easy.
npm install discretecrypt.jsjs
const Contact = DiscreteCrypt.Contact
// generates the contact ephemerally.
let me = Contact.create()
// the Contact.create().export() would happen on someone else's computer
let you = Contact.import(Contact.create().export())
// any JSON-serializable object can be passed into the "send" function.
me.send(you, 'Hello, World!').then(encrypted =>
{
// code to send encrypted data to other user
})
`
Then to open the data,
`js
you.open(encrypted).then(data =>
{
console.log(data) // Hello, World!
}).catch(err =>
{
// the decryption didn't occur correctly.
console.error(err)
})
`
#### Creating a Reusable Contact
To create a re-usable contact for public-key cryptography (one you can import at a later date), do the following:
1 - Create the Contact
`js
// you can also pass in an Buffer or Uint8-like object for the password.
let me = Contact.create('')
// creates the public contact, store this somewhere
let pub = me.export()
`
2 - Import the Public Contact & Compute (To turn it back into a private contact)
`js
let me = Contact.import(pub).compute('')
`
And that's it!
#### Symmetrically Encrypting Data
Sometimes you'll want to encrypt data symmetrically. These methods use a slight reduction of the DiscreteCrypt protocol (removing the asymmetric steps) that allow you to securely store a payload.
Out of the box these methods perform data authenticity checks, and the necessary key stretching to keep your data safe.
`js
// key can be a string, buffer or uint8array-like structure.
DiscreteCrypt.Symmetric.encrypt(key, data).then(encrypted =>
{
// store encrypted somewhere
// ... and then later on
DiscreteCrypt.Symmetric.decrypt(key, encrypted).then(decrypted =>
{
console.log(decrypted)
})
})
`
Documentation
Here is where you can view the rest of the documentation
To Build (for browser)
Run the following commands:
`
npm i
npm run build
``