crypto

package
v1.0.60 Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt added in v1.0.5

func Decrypt(publicKey *ecdh.PublicKey, privateKey *ecdh.PrivateKey, ciphertext []byte) ([]byte, error)

Decrypt decrypts data using AES-GCM with a shared secret derived from ECDH

func DecryptStream added in v1.0.13

func DecryptStream(reader io.Reader, writer io.WriteCloser, key string) error

DecryptStream decrypts data from a reader (like an HTTP response body) using a chunked approach where each chunk has its own nonce and authentication tag. This is secure for large files and streaming data sources. The format of each chunk is: [4-byte chunk size (little-endian)][nonce][encrypted data][tag]

func EncodePrivateKeyToPEM

func EncodePrivateKeyToPEM(privateKey *ecdh.PrivateKey) ([]byte, error)

EncodePrivateKeyToPEM converts an ECDH private key to PEM format using PKCS#8

func EncodePublicKeyToPEM

func EncodePublicKeyToPEM(publicKey *ecdh.PublicKey) ([]byte, error)

EncodePublicKeyToPEM converts an ECDH public key to PEM format using PKIX

func Encrypt added in v1.0.5

func Encrypt(publicKey *ecdh.PublicKey, privateKey *ecdh.PrivateKey, plaintext []byte) ([]byte, error)

Encrypt encrypts data using AES-GCM with a shared secret derived from ECDH

func EncryptStream added in v1.0.13

func EncryptStream(reader io.Reader, writer io.WriteCloser, key string) error

EncryptStream encrypts data from a reader using a chunked approach where each chunk has its own nonce and authentication tag. This is secure for large files and streaming data sources. The format of each chunk is: [4-byte chunk size (little-endian)][nonce][encrypted data][tag]

func ReadPrivateKey added in v1.0.7

func ReadPrivateKey(privateKey []byte) (*ecdh.PrivateKey, error)

ReadPrivateKey reads and parses an ECDH private key from pem encoded bytes

func ReadPrivateKeyFromFile

func ReadPrivateKeyFromFile(privateKeyPath string) (*ecdh.PrivateKey, error)

ReadPrivateKeyFromFile reads and parses an ECDH private key from a file

func ReadPublicKey added in v1.0.7

func ReadPublicKey(publicKey []byte) (*ecdh.PublicKey, error)

ReadPublicKey reads and parses an ECDH public key from pem encoded bytes

func ReadPublicKeyFromFile

func ReadPublicKeyFromFile(publicKeyPath string) (*ecdh.PublicKey, error)

ReadPublicKeyFromFile reads and parses an ECDH public key from a file

func WriteKeyPairToFiles

func WriteKeyPairToFiles(keyPair *KeyPair, privateKeyPath, publicKeyPath string) error

WriteKeyPairToFiles writes ECDH key pair to files with specified permissions

Types

type KeyPair added in v1.0.5

type KeyPair struct {
	PrivateKey *ecdh.PrivateKey
	PublicKey  *ecdh.PublicKey
}

KeyPair represents an ECDH key pair

func GenerateKeyPair added in v1.0.5

func GenerateKeyPair() (*KeyPair, error)

GenerateKeyPair generates a new ECDH key pair using P-256

Jump to

Keyboard shortcuts

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