symmetry

package
v0.0.8 Latest Latest
Warning

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

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

Documentation

Overview

Package symmetry provides symmetric cryptographic helpers for hashing, AES-GCM encryption, and Fernet-compatible tokens.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Blake3

func Blake3(message string) string

Blake3 returns the BLAKE3 digest of message encoded as standard Base64.

func DecodeFernet

func DecodeFernet(keyString, encryptedString string) (string, error)

DecodeFernet validates and decrypts a standard Fernet token.

It verifies the token structure, validates the HMAC-SHA256 signature, decrypts the ciphertext with AES-128-CBC, removes PKCS#7 padding, and returns the original plaintext.

func DecryptAES

func DecryptAES(symmetricalAccess, valorCifrado, additionalData string) (string, error)

DecryptAES decrypts payloads produced by EncryptAES using AES-GCM.

func EncodeFernet

func EncodeFernet(keyString, originalString string) (string, error)

EncodeFernet creates a standard Fernet token compatible with common Fernet implementations.

keyString must decode to exactly 32 bytes. The token includes version, timestamp, IV, AES-128-CBC ciphertext, and an HMAC-SHA256 signature, and is returned as URL-safe Base64.

func EncryptAES

func EncryptAES(symmetricalAccess, valorCampo, additionalData string) (string, error)

EncryptAES encrypts valorCampo using AES-GCM and returns a Base64 payload with this layout:

Base64( nonce | ciphertext_and_tag )

symmetricalAccess must be a Base64-encoded AES key whose decoded size is 16, 24, or 32 bytes.

func GenerateHMAC

func GenerateHMAC(message, secretKey string) string

GenerateHMAC computes an HMAC-SHA256 for message using secretKey and returns the digest encoded as standard Base64.

func Sha256Hex

func Sha256Hex(message string) string

Sha256Hex returns the SHA-256 digest of message encoded as hexadecimal.

func ValidateHMAC

func ValidateHMAC(message, secretKey, providedHash string) bool

ValidateHMAC reports whether providedHash matches the HMAC-SHA256 generated from message and secretKey.

Types

This section is empty.

Jump to

Keyboard shortcuts

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