NIP-44: Encrypted Payloads (Versioned)

Rust
use nostr_sdk::prelude::*;

pub fn run() -> Result<()> {
    let keys = Keys::generate();

    let pk =
        PublicKey::from_hex("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798")?;

    let ciphertext = nip44::encrypt(keys.secret_key(), &pk, "my message", nip44::Version::V2)?;
    println!("Encrypted: {ciphertext}");

    let plaintext = nip44::decrypt(keys.secret_key(), &pk, ciphertext)?;
    println!("Decrypted: {plaintext}");

    Ok(())
}
Python
from nostr_sdk import Keys, PublicKey, nip44_encrypt, nip44_decrypt, Nip44Version

def nip44():
    print("\nEncrypting and Decrypting Messages (NIP-44):")
    keys = Keys.generate()

    pk = PublicKey.from_hex("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798")

    ciphertext = nip44_encrypt(keys.secret_key(), pk, "my message", Nip44Version.V2)
    print(f" Encrypted: {ciphertext}")

    plaintext = nip44_decrypt(keys.secret_key(), pk, ciphertext)
    print(f" Decrypted: {plaintext}")
JavaScript
import {Keys, PublicKey, nip44Encrypt, nip44Decrypt, NIP44Version} from "@rust-nostr/nostr-sdk";

export function run() {
    let keys = Keys.generate();

    let public_key = PublicKey.fromHex("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798");

    let ciphertext = nip44Encrypt(keys.secretKey, public_key, "my message", NIP44Version.V2)
    console.log("Encrypted: " + ciphertext)

    let plaintext = nip44Decrypt(keys.secretKey, public_key, ciphertext)
    console.log("Decrypted: " + plaintext)
}
Kotlin

TODO

Swift
import Foundation
import NostrSDK

func nip44() throws {
    let keys = Keys.generate()

    let publicKey = try PublicKey.fromHex(hex: "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798")

    let ciphertext = try nip44Encrypt(secretKey: keys.secretKey(), publicKey: publicKey, content: "my message", version: Nip44Version.v2)
    print("Encrypted: \(ciphertext)");

    let plaintext = try nip44Decrypt(secretKey: keys.secretKey(), publicKey: publicKey, payload: ciphertext)
    print("Decrypted: \(plaintext)");
}
Flutter

TODO