# 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 transaction builder interface to handle encrypted operations.

# Using Direct Encryption and Decryption Methods

The encrypt and decrypt methods allow for straightforward encryption and decryption operations with explicit public keys. First argument is your opened beekeeper wallet instance, second argument is your content as string to be encrypted/decrypted, and then public key(s) used for encryption/decryption. Below are examples covering the case with one and two keys (sender key and receiver key):

import { createHiveChain } from "@hiveio/wax";

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

const hiveChain = await createHiveChain();
const content = "This is a secret message.";

// Encrypt the content - sender side
const encryptedContent = hiveChain.encrypt(wallet, content, publicKey1);

// Decrypt the content - receiver side
const decryptedContent = hiveChain.decrypt(wallet, encryptedContent);

console.log(decryptedContent); // This is a secret message.
import { createHiveChain } from "@hiveio/wax";

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

const hiveChain = await createHiveChain();
const content = "This is a secret message.";

// Encrypt the content using two keys - sender side
const encryptedContent = hiveChain.encrypt(wallet, content, publicKey1, publicKey2);

// Decrypt the content - receiver side
const decryptedContent = hiveChain.decrypt(wallet, encryptedContent);

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