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 ¶
- func AESGCMDecrypt(ciphertext, key []byte) ([]byte, error)
- func AESGCMEncrypt(plaintext, key []byte) ([]byte, error)
- func GenerateKey() []byte
- func GenerateRandomBytes(length int) ([]byte, error)
- func HMAC(data, key []byte, hasher func() hash.Hash) []byte
- func HMACSHA256(data, key []byte) string
- func Hash(data []byte, hasher hash.Hash) []byte
- func SHA256(data []byte) string
- func SHA512(data []byte) string
- func SecureCompare(a, b []byte) bool
- func SecureCompareString(a, b string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AESGCMDecrypt ¶
AESGCMDecrypt decrypts data using AES-GCM.
func AESGCMEncrypt ¶
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 ¶
GenerateRandomBytes generates cryptographically secure random bytes.
func HMACSHA256 ¶
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 ¶
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 SecureCompare ¶
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 ¶
SecureCompareString performs constant-time string comparison.
Types ¶
This section is empty.