decrypt()

Othent JS SDK decrypt() function

The decrypt() function allows applications to decrypt data that has been encrypted using the active user's private key, similarly to the Web Crypto API's decrypt()arrow-up-right.

triangle-exclamation
circle-exclamation

API

decrypt(ciphertext: BinaryDataType): Promise<Uint8Array>;

ciphertext: BinaryDataType

The data to be decrypted with the user's private key, which can be of type ArrayBufferarrow-up-right, TypedArrayarrow-up-right or DataViewarrow-up-right.

return Promise<Uint8Array>

A Promise containing the decrypted data as Uint8Arrayarrow-up-right.

Example usage

import { Othent } from "@othent/kms";

const othent = new Othent({ appInfo, throwErrors: false, ... });

// Make sure the user is authenticated, or prompt them to authenticate:
await othent.requireAuth();

// Encrypt data using RSA:
const encrypted = await othent.encrypt("This message will be encrypted");

console.log("Encrypted bytes:", encrypted);

// Decrypt the same data using RSA:
const decrypted = await othent.decrypt(encrypted);
const decryptedString = new TextDecoder().decode(decrypted);

console.log(`The original secret message is "${ decryptedString }".`);

Last updated