encrypt()
Othent JS SDK encrypt() function
The encrypt()
function encrypts the data using the active user's private key so that, when stored on Arweave, it is only accessible to that specific user, similarly to the Web Crypto API's encrypt()
.
This is useful for applications such as private file storage apps or mail/messaging platforms.
Limitation: There's currently an 8KB limit in data size when using Othent, but this is currently being worked on. Track the progress on this GitHub issue.
Limitation: Also, the only currently available encryption/decryption algorithm is AES (AES256-GCM
).
This function assumes (and requires) a user is authenticated. See requireAuth()
.
API
encrypt(plaintext: string | BinaryDataType): Promise<Uint8Array>;
plaintext: string | BinaryDataType
plaintext: string | BinaryDataType
The data to be encrypted with the user's private key, which can be of type string
, ArrayBuffer
, TypedArray
or DataView
.
return Promise<Uint8Array>
return Promise<Uint8Array>
A Promise
containing the encrypted data as Uint8Array
.
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);
Last updated