encryption

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package encryption provides functionalities for secure message encryption using the NaCl (Networking and Cryptography library) authenticated encryption scheme.

It includes methods for encrypting messages, handling version information, and verifying the validity of version strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsVersion

func IsVersion(version string) bool

IsVersion returns true if given value is a valid Version.

Types

type EncryptedMessage

type EncryptedMessage struct {
	Version            Version `json:"version"`
	Nonce              []byte  `json:"nonce"`
	EphemeralPublicKey []byte  `json:"ephemPublicKey"`
	Ciphertext         []byte  `json:"ciphertext"`
}

EncryptedMessage represents an encrypted message with additional meta-information.

func Encrypt

func Encrypt(encryptionKey [32]byte, message []byte) (EncryptedMessage, error)

Encrypt encrypts a message using VersionNaClAuthenticated encryption version.

func EncryptWithPadding

func EncryptWithPadding(encryptionKey [32]byte, message any) (EncryptedMessage, error)

EncryptWithPadding encrypts a message in a way that obscures the message length.

The message is padded to a multiple of 2048 before being encrypted so that the length of the resulting encrypted message can't be used to guess the exact length of the original message.

Source: https://github.com/MetaMask/eth-sig-util/blob/10206bf2f16f0b47b1f2da9a9cfbb39c6a7a7800/src/encryption.ts#L94

type Version

type Version string

Version represents a string that indicates the set of used cryptography algorithms.

const VersionNaClAuthenticated Version = "x25519-xsalsa20-poly1305"

VersionNaClAuthenticated uses Curve25519, XSalsa20 and Poly1305 to encrypt and authenticate messages.

func (Version) MarshalText

func (s Version) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler.

func (Version) String

func (v Version) String() string

String returns the string representation of the Version value.

func (*Version) UnmarshalText

func (s *Version) UnmarshalText(value []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

Jump to

Keyboard shortcuts

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