How to use the libsodium-wrappers.to_string function in libsodium-wrappers

To help you get started, we’ve selected a few libsodium-wrappers 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 Picolab / pico-engine / packages / pico-engine-core / src / modules / indy.js View on Github external
case 'Authcrypt':
        if (!senderVK) {
          throw new Error('Sender public key not provided in Authcrypt message')
        }
        break
      case 'Anoncrypt':
        break
      default:
        throw new Error(`Unsupported pack algorithm: ${recipsOuter.alg}`)
    }

    const ciphertext = b64dec(wrapper.ciphertext)
    nonce = b64dec(wrapper.iv)
    const mac = b64dec(wrapper.tag)

    const message = sodium.to_string(
      sodium.crypto_aead_chacha20poly1305_ietf_decrypt_detached(
        null, // nsec
        ciphertext,
        mac,
        wrapper.protected, // ad
        nonce, // npub
        cek
      )
    )

    return {
      message,
      sender_key: senderVK,
      recipient_key: recipient.header.kid
    }
  })
github Picolab / pico-engine / packages / pico-engine-core / src / modules / indy.js View on Github external
function b64decStr (input) {
  return sodium.to_string(sodium.from_base64(input, sodium.base64_variants.URLSAFE))
}
github TankerHQ / sdk-js / packages / crypto / src / utils.js View on Github external
export function toString(bytes: Uint8Array): string {
  if (!(bytes instanceof Uint8Array))
    throw new TypeError('"bytes" is not a Uint8Array');

  return sodium.to_string(bytes);
}
github whs / ipfs-encrypted-share / src / lib / browserdecrypt.js View on Github external
decryptMetadata(data) {
		if (this.metadata) {
			return this.metadata;
		}

		let header = sodium.from_base64(data.header, sodium.base64_variants.ORIGINAL_NO_PADDING);
		let encryptedMetadata = sodium.from_base64(data.encryptedMetadata, sodium.base64_variants.ORIGINAL_NO_PADDING);
		this.state = sodium.crypto_secretstream_xchacha20poly1305_init_pull(header, this.key);
		let { message, tag } = sodium.crypto_secretstream_xchacha20poly1305_pull(this.state, encryptedMetadata);
		message = JSON.parse(sodium.to_string(message));

		if (tag !== sodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL) {
			throw new Error('metadata chunk not ended with final tag');
		}

		this.metadata = Object.assign({}, data, message);

		return this.metadata;
	}