# Encrypt buffer

The Wax library provides a robust set of tools for handling encryption and decryption within the Hive ecosystem. This includes both methods for direct encryption/decryption as well as using the ITransaction interface to handle encrypted operations.

# Using Direct Encryption and Decryption Methods

The signer's encryptData and decryptData methods allow for straightforward encryption and decryption operations with explicit public keys. You provide the content as a string to be encrypted/decrypted, and the public key(s) used for encryption/decryption. Below are examples covering the case with one and two keys (sender key and receiver key):

# One key encryption

/* Import preconfigured beekeeper data specific to snippet examples */
const { signer1, publicKey1 } = globalThis.snippetsBeekeeperData;

const content = "This is a secret message.";

// Encrypt the content - sender side
// Note that signer1 holds the private key for publicKey1
const encryptedContent = await signer1.encryptData(content, publicKey1);

// Decrypt the content - receiver side
const decryptedContent = await signer1.decryptData(encryptedContent);

console.log(decryptedContent); // This is a secret message.

Not implemented yet — planned for a future release.

# Two keys encryption

/* Import preconfigured beekeeper data specific to snippet examples */
const { signer1, signer2, publicKey2 } = globalThis.snippetsBeekeeperData;

const content = "This is a secret message.";

// Pre-encrypt data for the second signer - sender side
const encryptedContent = await signer1.encryptData(content, publicKey2);

// Decrypt the content - receiver side
const decryptedContent = await signer2.decryptData(encryptedContent);

console.log(decryptedContent); // This is a secret message.

Not implemented yet — planned for a future release.