Links

Encrypt

ArConnect Injected API encrypt() function
Some applications (such as private file storage apps, mail clients, messaging platforms) might want to upload content to Arweave that is encrypted and only accessible by the user via their private key. The encrypt() function does just that: it encrypts data with the active private key and returns the encrypted bytes, similarly to the webcrypto encrypt API.
Argument
Type
Description
data
The data to be encrypted with the user's private key
algorithm
An object specifying the algorithm to be used and any extra parameters if required
Note: This function requires the ENCRYPT permission.

Example usage

// connect to the extension
await window.arweaveWallet.connect(["ENCRYPT"]);
// encrypt data using RSA-OAEP
const encrypted = await arweaveWallet.encrypt(
new TextEncoder().encode("This message will be encrypted"),
{ name: "RSA-OAEP" }
);
console.log("Encrypted bytes:", encrypted);

Old (deprecated) usage

// connect to the extension
await window.arweaveWallet.connect(["ENCRYPT"]);
// encrypt data
const encrypted = await window.arweaveWallet.encrypt(
new TextEncoder().encode("This message will be encrypted"),
{
algorithm: "RSA-OAEP",
hash: "SHA-256",
}
);
console.log("Encrypted bytes", encrypted);