Skip to main content

Overview

The Memo utility provides AES encryption and decryption for private messages between Hive users. It uses ECDH (Elliptic Curve Diffie-Hellman) key exchange to derive shared secrets and AES encryption for secure communication. Messages must start with # to be encrypted/decrypted. Plain text messages (without #) are returned unchanged.

Methods

encode

Encrypts a memo using AES encryption for secure private messaging on Hive.
string | PrivateKey
required
Sender’s private memo key (WIF string or PrivateKey instance)
string | PublicKey
required
Recipient’s public memo key (string or PublicKey instance)
string
required
Message to encrypt. Must start with # for encryption. Plain text (without #) is returned unchanged.
any
Optional nonce for testing purposes (advanced usage)
string
Encrypted memo string prefixed with #, or original string if not encrypted

Example

decode

Decrypts an encrypted memo using AES decryption.
string | PrivateKey
required
Recipient’s private memo key (WIF string or PrivateKey instance)
string
required
Encrypted memo string. Must start with # for decryption. Plain text (without #) is returned unchanged.
string
Decrypted memo content with # prefix, or original string if not encrypted

Example

Complete Example: Encrypted Transfer

Decrypting Received Memos

Bidirectional Encryption

Memos can be decrypted by both sender and recipient:

Unicode Support

Memos fully support Unicode characters:

Fetching Public Memo Keys

To encrypt a memo, you need the recipient’s public memo key:

Error Handling

Plain Text vs Encrypted

Memos without the # prefix are treated as plain text:

Security Considerations

Memo Security Best Practices:
  1. Use memo keys only: Never use active or owner keys for memo encryption
  2. Memo key compromise: If your memo key is compromised, past encrypted memos can be decrypted
  3. Public visibility: Encrypted memos are visible on the blockchain, only the content is encrypted
  4. Key management: Store memo private keys securely, separate from other keys
  5. Sensitive data: Avoid putting highly sensitive data in memos; they’re not as secure as off-chain encryption

Secure Memo Example

How It Works

Memo encryption uses the following process:
  1. Shared Secret: ECDH key exchange between sender’s private memo key and recipient’s public memo key creates a shared secret
  2. AES Encryption: The message is encrypted with AES using the shared secret as the key
  3. Nonce: A random nonce ensures different ciphertexts for identical messages
  4. Checksum: A checksum is included to detect corruption
  5. Base58 Encoding: The encrypted data is encoded in Base58 for transmission
  6. Format: #[base58_encoded(from_key + to_key + nonce + checksum + encrypted_message)]

Type Definition

See Also