How to use the libsodium-wrappers-sumo.from_string function in libsodium-wrappers-sumo

To help you get started, we’ve selected a few libsodium-wrappers-sumo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wireapp / wire-web-packages / packages / proteus / spec / derived / MacKeySpec.ts View on Github external
it('encodes a message', () => {
    const key_material_buffer = new ArrayBuffer(32);
    const typed_key_material = new Uint8Array(key_material_buffer);
    const mac_key = new Proteus.derived.MacKey(typed_key_material);
    const message = sodium.from_string('hello');

    const authentication_code = mac_key.sign(message);

    // prettier-ignore
    const expected = new Uint8Array([67, 82, 178, 110, 51, 254, 13, 118, 154, 137, 34, 166, 186, 41, 0, 65, 9, 240, 22, 136, 226, 106, 204, 158, 108, 179, 71, 229, 165, 175, 196, 218]);

    expect(authentication_code).toEqual(expected);
  });
github wireapp / wire-web-packages / packages / proteus / spec / derived / DerivedSecretsSpec.ts View on Github external
it('can encrypt and decrypt text', () => {
    const info = 'foobar';
    const input = sodium.from_string('346234876');
    const nonce = sodium.from_string('00000000');
    const plain_text = sodium.from_string('plaintext');

    const derived_secret = Proteus.derived.DerivedSecrets.kdf_without_salt(input, info);

    const encrypted_text = derived_secret.cipher_key.encrypt(plain_text, nonce);
    expect(encrypted_text).not.toEqual(plain_text);

    const decrypted_text = derived_secret.cipher_key.decrypt(encrypted_text, nonce);
    expect(decrypted_text).toEqual(plain_text);
  });
});
github wireapp / wire-web-packages / packages / proteus / spec / derived / DerivedSecretsSpec.ts View on Github external
it('can encrypt and decrypt text', () => {
    const info = 'foobar';
    const input = sodium.from_string('346234876');
    const nonce = sodium.from_string('00000000');
    const plain_text = sodium.from_string('plaintext');

    const derived_secret = Proteus.derived.DerivedSecrets.kdf_without_salt(input, info);

    const encrypted_text = derived_secret.cipher_key.encrypt(plain_text, nonce);
    expect(encrypted_text).not.toEqual(plain_text);

    const decrypted_text = derived_secret.cipher_key.decrypt(encrypted_text, nonce);
    expect(decrypted_text).toEqual(plain_text);
  });
});
github wireapp / wire-web-packages / packages / proteus / spec / derived / DerivedSecretsSpec.ts View on Github external
it('can encrypt and decrypt text', () => {
    const info = 'foobar';
    const input = sodium.from_string('346234876');
    const nonce = sodium.from_string('00000000');
    const plain_text = sodium.from_string('plaintext');

    const derived_secret = Proteus.derived.DerivedSecrets.kdf_without_salt(input, info);

    const encrypted_text = derived_secret.cipher_key.encrypt(plain_text, nonce);
    expect(encrypted_text).not.toEqual(plain_text);

    const decrypted_text = derived_secret.cipher_key.decrypt(encrypted_text, nonce);
    expect(decrypted_text).toEqual(plain_text);
  });
});
github wireapp / wire-web-packages / packages / proteus / spec / derived / MacKeySpec.ts View on Github external
it('verifies calculated data', async () => {
    const mac_key = new Proteus.derived.MacKey(new Uint8Array(32).fill(1));
    const msg = sodium.from_string('This is my great message in Proteus!');
    const signature = mac_key.sign(msg);

    expect(mac_key.verify(signature, msg)).toBe(true);
  });
});
github TankerHQ / quickstart-examples / server / src / auth.js View on Github external
const generatePasswordResetToken = ({ userId, secret }) => {
  const asString = JSON.stringify({ userId, secret });
  const buf = sodium.from_string(asString);
  return sodium.to_base64(buf);
};