encryption

package
v0.27.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2025 License: Unlicense, MIT Imports: 17 Imported by: 0

README

NIP-44 implementation in Go

NIP-44 specification: https://github.com/nostr-protocol/nips/blob/master/44.md

To use as library: go get -u github.com/ekzyis/nip44

To run tests, clone repository and then run go test.

Documentation

Overview

Package encryption contains the message encryption schemes defined in NIP-04 and NIP-44, used for encrypting the content of nostr messages.

Index

Constants

This section is empty.

Variables

View Source
var (
	MinPlaintextSize = 0x0001 // 1b msg => padded to 32b
	MaxPlaintextSize = 0xffff // 65535 (64kb-1) => padded to 64kb
)

Functions

func Decrypt

func Decrypt(conversationKey []byte, ciphertext string) (plaintext string, err error)

func DecryptNip4

func DecryptNip4(content, key []byte) (msg []byte, err error)

DecryptNip4 decrypts a content string using the shared secret key. The inverse operation to message -> EncryptNip4(message, key).

func Encrypt

func Encrypt(conversationKey []byte, plaintext []byte, options *EncryptOptions) (ciphertext string, err error)

func EncryptNip4

func EncryptNip4(msg, key []byte) (ct []byte, err error)

EncryptNip4 encrypts message with key using aes-256-cbc. key should be the shared secret generated by ComputeSharedSecret.

Returns: base64(encrypted_bytes) + "?iv=" + base64(initialization_vector).

func GenerateConversationKey added in v0.25.3

func GenerateConversationKey(sendPrivkey []byte, recvPubkey []byte) (conversationKey []byte, err error)

func MessageKeys added in v0.25.3

func MessageKeys(conversationKey []byte, salt []byte) ([]byte, []byte, []byte, error)

Types

type EncryptOptions added in v0.25.3

type EncryptOptions struct {
	Salt    []byte
	Version int
}

Source Files

  • doc.go
  • nip4.go
  • nip44.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL