encryption

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareWithHash

func CompareWithHash(HashedString string, Password string) bool

CompareWithHash verifies a plain text password against a bcrypt hash. Returns true if the password matches the hash, false otherwise.

func CreateHash

func CreateHash(Password string) (string, error)

CreateHash generates a bcrypt hash from a plain text password. Returns the hashed password as a string or an error if hashing fails.

func CreateHashWithCost added in v1.3.7

func CreateHashWithCost(Password string, cost int) (string, error)

CreateHashWithCost generates a bcrypt hash with a custom cost factor. Higher cost factors are more secure but slower.

func Decrypt

func Decrypt(encryptedData models.EncryptReturnType) (interface{}, error)

Decrypt decrypts AES-encrypted data in CBC mode and returns the original data. Supports Base64 or hex-encoded input. Returns the decrypted data or an error if decryption fails.

func DecryptBytes added in v1.3.7

func DecryptBytes(encryptedData models.EncryptReturnType) ([]byte, error)

DecryptBytes is a convenience function for decrypting to byte data.

func DecryptString added in v1.3.7

func DecryptString(encryptedData models.EncryptReturnType) (string, error)

DecryptString is a convenience function for decrypting to string data.

func Encrypt

func Encrypt(data interface{}) (*models.EncryptReturnType, error)

Encrypt encrypts data using AES in CBC mode and returns an encoded payload. Supports Base64 or hex encoding for the ciphertext. Returns the encrypted payload or an error if encryption fails.

func EncryptBytes added in v1.3.7

func EncryptBytes(data []byte) (*models.EncryptReturnType, error)

EncryptBytes is a convenience function for encrypting byte data.

func EncryptString added in v1.3.7

func EncryptString(data string) (*models.EncryptReturnType, error)

EncryptString is a convenience function for encrypting string data.

func GenerateEncryptionKey added in v1.3.7

func GenerateEncryptionKey(keySize int) (string, error)

GenerateEncryptionKey generates a cryptographically secure random encryption key.

func GenerateIV added in v1.3.7

func GenerateIV() (string, error)

GenerateIV generates a cryptographically secure random initialization vector.

func GenerateRefreshToken added in v1.4.1

func GenerateRefreshToken() (string, error)

GenerateRefreshToken generates a cryptographically secure random token

func GetHashInfo added in v1.3.7

func GetHashInfo(hashedString string) (cost int, err error)

GetHashInfo returns basic information about a bcrypt hash.

func GetRecommendedCost added in v1.3.7

func GetRecommendedCost() int

GetRecommendedCost returns the recommended bcrypt cost factor for the current system. This can be used to automatically adjust cost based on system performance.

func GetSupportedEncryptionTypes added in v1.3.7

func GetSupportedEncryptionTypes() []string

GetSupportedEncryptionTypes returns the supported encryption encoding types.

func GetSupportedKeySizes added in v1.3.7

func GetSupportedKeySizes() []int

GetSupportedKeySizes returns the supported AES key sizes.

func HashAndVerify added in v1.3.7

func HashAndVerify(Password string) (string, error)

HashAndVerify generates a hash and immediately verifies it against the original password. This is useful for ensuring the hash was generated correctly.

func HashToken added in v1.4.1

func HashToken(token string) string

HashToken creates a SHA-256 hash of a token

func IsHashValid added in v1.3.7

func IsHashValid(hashedString string) bool

IsHashValid checks if a string appears to be a valid bcrypt hash.

func NeedsRehash added in v1.3.7

func NeedsRehash(hashedString string, minCost int) (bool, error)

NeedsRehash checks if a hash needs to be rehashed with a higher cost factor.

func ValidateEncryptionKey added in v1.3.7

func ValidateEncryptionKey(key string) error

ValidateEncryptionKey validates if a key is suitable for AES encryption.

func ValidateIV added in v1.3.7

func ValidateIV(iv string) error

ValidateIV validates if an initialization vector is suitable for AES encryption.

func ValidateTokenHash added in v1.4.1

func ValidateTokenHash(token, hash string) bool

ValidateTokenHash compares a token with its hash

Types

This section is empty.

Jump to

Keyboard shortcuts

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