Socket
Socket
Sign inDemoInstall

libsodium

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libsodium - npm Package Compare versions

Comparing version 0.7.2 to 0.7.3

2

package.json
{
"name": "libsodium",
"version": "0.7.2",
"version": "0.7.3",
"description":

@@ -5,0 +5,0 @@ "The Sodium cryptographic library compiled to pure JavaScript (raw library, no wrappers)",

@@ -98,8 +98,5 @@ # libsodium.js

A `sodium` object should be defined in the global namespace, with the
following properties:
following property:
- `onload`: the function to call after the wrapper is initialized.
- `totalMemory` (optional): the maximum amount of memory that sodium can use.
The default value should be fine for most applications, unless you
need to use password hashing functions with a large amount of memory.

@@ -120,23 +117,2 @@ Example:

## List of wrapped APIs:
* [`crypto_aead`](https://download.libsodium.org/doc/secret-key_cryptography/aead.html)
* [`crypto_auth`](https://download.libsodium.org/doc/secret-key_cryptography/secret-key_authentication.html)
* [`crypto_box`](https://doc.libsodium.org/public-key_cryptography/authenticated_encryption.html)
* [`crypto_box_seal`](https://download.libsodium.org/libsodium/content/public-key_cryptography/sealed_boxes.html)
* [`crypto_generichash`](https://download.libsodium.org/libsodium/content/hashing/generic_hashing.html)
* [`crypto_hash`](https://download.libsodium.org/libsodium/content/advanced/sha-2_hash_function.html)
* [`crypto_kdf`](https://download.libsodium.org/doc/key_derivation/)
* [`crypto_kx`](https://download.libsodium.org/doc/key_exchange/)
* [`crypto_onetimeauth`](https://download.libsodium.org/doc/advanced/poly1305.html)
* [`crypto_pwhash`](https://download.libsodium.org/libsodium/content/password_hashing/)
* [`crypto_scalarmult`](https://download.libsodium.org/libsodium/content/advanced/scalar_multiplication.html)
* [`crypto_secretbox`](https://download.libsodium.org/libsodium/content/secret-key_cryptography/authenticated_encryption.html)
* [`crypto_secretstream`](https://download.libsodium.org/doc/secret-key_cryptography/secretstream.html)
* [`crypto_shorthash`](https://download.libsodium.org/libsodium/content/hashing/short-input_hashing.html)
* [`crypto_sign`](https://download.libsodium.org/libsodium/content/public-key_cryptography/public-key_signatures.html)
* [`crypto_stream`](https://download.libsodium.org/doc/advanced/stream_ciphers.html)
* [Ed25519->Curve25519 conversion](https://download.libsodium.org/libsodium/content/advanced/ed25519-curve25519.html)
* [`randombytes`](https://download.libsodium.org/libsodium/content/generating_random_data/)
## Additional helpers

@@ -170,2 +146,3 @@

Example:
```javascript

@@ -180,36 +157,19 @@ var key = sodium.randombytes_buf(sodium.crypto_shorthash_KEYBYTES),

However, an extra parameter can be given to all wrapped functions, in
order to specify what format the output should be in. Valid options
are `uint8array' (default), 'text', 'base64' and 'hex'.
Example (shorthash):
```javascript
var key = sodium.randombytes_buf(sodium.crypto_shorthash_KEYBYTES),
hash_hex = sodium.crypto_shorthash('test', key, 'hex');
```
Example (secretbox):
```javascript
// Load your secret key from a safe place and reuse it across multiple
// secretbox calls. (Obviously don't use this example key for anything
// real.)
//
var secret = Buffer.from('724b092810ec86d7e35c9d067702b31ef90bc43a7b598626749914d6a3e033ed', 'hex');
let key = sodium.from_hex('724b092810ec86d7e35c9d067702b31ef90bc43a7b598626749914d6a3e033ed');
// Given a message as a string, return a Buffer containing the
// nonce (in the first 24 bytes) and the encrypted content.
var encrypt = function(message) {
// You must use a different nonce for each message you encrypt.
var nonce = Buffer.from(sodium.randombytes_buf(sodium.crypto_box_NONCEBYTES));
var buf = Buffer.from(message);
return Buffer.concat([nonce, Buffer.from(sodium.crypto_secretbox_easy(buf, nonce, secret))]);
},
function encrypt_and_prepend_nonce(message) {
let nonce = sodium.randombytes_buf(sodium.crypto_secretbox_NONCEBYTES);
return nonce.concat(sodium.crypto_secretbox_easy(message, nonce, key));
}
// Decrypt takes a Buffer and returns the decrypted message as plain text.
var decrypt = function(encryptedBuffer) {
var nonce = encryptedBuffer.slice(0, sodium.crypto_box_NONCEBYTES);
var encryptedMessage = encryptedBuffer.slice(sodium.crypto_box_NONCEBYTES);
return sodium.crypto_secretbox_open_easy(encryptedMessage, nonce, secret, 'text');
function decrypt_after_extracting_nonce(nonce_and_ciphertext) {
if (nonce_and_ciphertext.length < sodium.crypto_secretbox_NONCEBYTES + sodium.crypto_secretbox_MACBYTES) {
throw "Short message";
}
let nonce = nonce_and_ciphertext.slice(0, sodium.crypto_secretbox_NONCEBYTES),
ciphertext = nonce_and_ciphertext.slice(sodium.crypto_secretbox_NONCEBYTES);
return sodium.crypto_secretbox_open_easy(ciphertext, nonce, key);
}

@@ -216,0 +176,0 @@ ```

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc