Documentation
¶
Index ¶
- Constants
- Variables
- func ComputeHMACSHA256(data []byte, secret string) string
- func DecryptAESGCM(encoded string, key []byte) ([]byte, error)
- func DecryptAESGCMAAD(encoded string, key, aad []byte) ([]byte, error)
- func DeriveKey(master []byte, label string) ([]byte, error)
- func EncryptAESGCM(plaintext, key []byte) (string, error)
- func EncryptAESGCMAAD(plaintext, key, aad []byte) (string, error)
- func GeneratePKCE() (verifier string, challenge string, err error)
- func RandomBase64URL(n int) string
- func RandomHex(n int) string
- func SHA256Hex(data []byte) string
- func VerifyHMACSHA256(data []byte, secret, expectedHex string) bool
Constants ¶
const MinHMACKeyBytes = 16
MinHMACKeyBytes is the floor for supplied HMAC signing secrets; generated ones use 32 bytes.
Variables ¶
var ErrCiphertextTooShort = errors.New("crypto: ciphertext too short")
ErrCiphertextTooShort reports a payload shorter than the AES-GCM nonce it must start with.
var ErrKeyLength = errors.New("crypto: AES-256-GCM key must be exactly 32 bytes")
ErrKeyLength reports an AES-256-GCM key that is not exactly 32 bytes.
Functions ¶
func ComputeHMACSHA256 ¶
ComputeHMACSHA256 computes HMAC-SHA256 hex string.
func DecryptAESGCM ¶
DecryptAESGCM reverses EncryptAESGCM.
func DecryptAESGCMAAD ¶
DecryptAESGCMAAD reverses EncryptAESGCMAAD.
func DeriveKey ¶
DeriveKey is HKDF-SHA256(master, no salt, label) to 32 bytes, the convention internal/drive uses, so a value sealed for one purpose never opens under another. Stored data depends on the exact output: never change it.
func EncryptAESGCM ¶
EncryptAESGCM encrypts plaintext with AES-256-GCM under a 32-byte key and a random 12-byte nonce, returning nonce||ciphertext as raw base64url.
func EncryptAESGCMAAD ¶
EncryptAESGCMAAD is EncryptAESGCM authenticating aad too; decrypting needs the same aad.
func GeneratePKCE ¶
GeneratePKCE creates a PKCE code_verifier and code_challenge (S256).
func RandomBase64URL ¶
RandomBase64URL generates a cryptographically secure URL-safe base64 string.
func RandomHex ¶
RandomHex generates a cryptographically secure random hex string of 2*n characters.
func VerifyHMACSHA256 ¶
VerifyHMACSHA256 verifies HMAC-SHA256 signature in constant time.
Types ¶
This section is empty.