#hive #memo #encryption #aes #encryption-decryption #shared-secret #hive-blockchain

hive_memo

A crate for encrypting and decrypting Hive Blockchain memos using elliptic curve cryptography and AES

3 releases

0.1.2 Sep 24, 2024
0.1.1 Sep 24, 2024
0.1.0 Sep 23, 2024

#17 in #hive

MIT/Apache

23KB
350 lines

Hive Memo

Crates.io License

Hive Memo is a Rust crate designed for encrypting and decrypting memos using elliptic curve cryptography (ECC) and AES-256-CBC encryption, taking @hiveo/dhive's memo encryption and decryption methods into account.

Features

  • Key Management

    • Parse and validate WIF (Wallet Import Format) private keys.
    • Handle public keys in Hive format (STM prefixed).
    • Derive public keys from private keys.
  • Encryption & Decryption

    • Encrypt memos using AES-256-CBC with shared secrets derived from ECDH.

Installation

Add hive_memo to your Cargo.toml:

[dependencies]
hive_memo = "0.1.0"

OR

cargo add hive_memo

Usage

Encryption

use hive_memo::keys::{wif_to_secret_key, public_key_from_string};
use hive_memo::encryption::encrypt_memo;
use std::error::Error;


fn main()  {
    // Sender's WIF private key
    let sender_private_wif = "5KV4qZ1obXQPwUQqitD5Tx86Writ4tbeDAo68WLXhcU3ZaHR1M7";
    // Receiver's public key in Hive format
    let receiver_public_key_str = "STM5PQVrcekY3psFdYxRDXtYRNNWsPjeHtTvfhUtKaiADPvRqSVYM";


    // Convert WIF to SecretKey
    let sender_private_key = wif_to_secret_key(sender_private_wif)?;
    // Convert Hive public key string to PublicKey
    let receiver_public_key = public_key_from_string(receiver_public_key_str)?;


    let memo = "#This is a secure memo";


    // Encrypt the memo
    let encrypted_memo = encrypt_memo(&sender_private_key, &receiver_public_key, memo)?;
    println!("Encrypted Memo: {}", encrypted_memo);
}


Decryption

use hive_memo::keys::wif_to_secret_key;
use hive_memo::encryption::decrypt_memo;
use std::error::Error;


fn main() {
    // Receiver's WIF private key
    let receiver_private_wif = "5KV4qZ1obXQPwUQqitD5Tx86Writ4tbeDAo68WLXhcU3ZaHR1M7";
    // Encrypted memo string
    let encrypted_memo = "#<Base58EncodedEncryptedMemo>";


    // Convert WIF to SecretKey
    let receiver_private_key = wif_to_secret_key(receiver_private_wif)?;


    // Decrypt the memo
    let decrypted_memo = decrypt_memo(&receiver_private_key, encrypted_memo)?;
    println!("Decrypted Memo: {}", decrypted_memo);
}

Dependencies

~9.5MB
~139K SLoC