cryptoutils

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package cryptoutils provides cryptographic utilities using secure standard library functions. I've removed all the weak stuff (MD5, SHA1, etc.) after reading too many security articles. Seriously, if I see one more "just use bcrypt" comment...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESGCMDecrypt

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

AESGCMDecrypt decrypts data using AES-GCM.

func AESGCMEncrypt

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

AESGCMEncrypt encrypts data using AES-GCM with random nonce. AES-GCM is pretty solid - provides both confidentiality and authenticity Unlike my life choices

func GenerateKey

func GenerateKey() []byte

GenerateKey generates a 32-byte cryptographically secure key. 32 bytes = 256 bits which should be plenty Unless the NSA is after your cat photos

func GenerateRandomBytes

func GenerateRandomBytes(length int) ([]byte, error)

GenerateRandomBytes generates cryptographically secure random bytes.

func HMAC

func HMAC(data, key []byte, hasher func() hash.Hash) []byte

HMAC computes HMAC using the specified hash function.

func HMACSHA256

func HMACSHA256(data, key []byte) string

HMACSHA256 computes HMAC-SHA256 and returns hex-encoded string. Convenience function since I use this combo a lot Naming is hard but at least it's descriptive

func Hash

func Hash(data []byte, hasher hash.Hash) []byte

Hash computes a cryptographic hash using the specified hasher. Generic function - probably overkill but wanted to learn how to do it Also makes me feel smart about interfaces

func SHA256

func SHA256(data []byte) string

SHA256 computes SHA256 hash and returns hex-encoded string.

func SHA512

func SHA512(data []byte) string

SHA512 computes SHA512 hash and returns hex-encoded string.

func SecureCompare

func SecureCompare(a, b []byte) bool

SecureCompare performs constant-time comparison to prevent timing attacks. Learned about this from a security blog - timing attacks are scary! Like, who even thinks of measuring response times to break crypto?

func SecureCompareString

func SecureCompareString(a, b string) bool

SecureCompareString performs constant-time string comparison.

Types

This section is empty.

Jump to

Keyboard shortcuts

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