crypto

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptAESGCM

func DecryptAESGCM(ciphertext, key []byte) ([]byte, error)

DecryptAESGCM reverses EncryptAESGCM.

func DecryptAESGCMWithAAD

func DecryptAESGCMWithAAD(ciphertext, key, additionalData []byte) ([]byte, error)

DecryptAESGCMWithAAD reverses EncryptAESGCMWithAAD. It returns an error if the ciphertext was tampered with or additionalData does not match.

func DeriveKey

func DeriveKey(master []byte, info string) ([]byte, error)

DeriveKey derives a 32-byte subkey from a master secret for a specific use (e.g. "key-encryption"), using HKDF-SHA256. Domain separation means a single configured secret cannot be silently reused across two cryptographic contexts: the same master yields independent keys for different info labels.

func EncryptAESGCM

func EncryptAESGCM(plaintext, key []byte) ([]byte, error)

EncryptAESGCM encrypts plaintext with AES-256-GCM. The nonce is prepended to the returned ciphertext.

func EncryptAESGCMWithAAD

func EncryptAESGCMWithAAD(plaintext, key, additionalData []byte) ([]byte, error)

EncryptAESGCMWithAAD encrypts plaintext with AES-256-GCM, additionally authenticating (but not encrypting) additionalData. Binding AAD — e.g. a key id and use-type — to a stored ciphertext makes it tamper-evident and prevents a row from being swapped for another key's ciphertext: decryption fails unless the exact same AAD is supplied.

func GenerateRSAKey

func GenerateRSAKey(bits int) (*rsa.PrivateKey, error)

func MarshalPrivateKeyPEM

func MarshalPrivateKeyPEM(key *rsa.PrivateKey) []byte

func MarshalPublicKeyPEM

func MarshalPublicKeyPEM(key *rsa.PublicKey) ([]byte, error)

func ParsePrivateKeyPEM

func ParsePrivateKeyPEM(data []byte) (*rsa.PrivateKey, error)

func RandomBytes

func RandomBytes(n int) ([]byte, error)

func RandomHex

func RandomHex(n int) (string, error)

func RandomString

func RandomString(n int) (string, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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