Documentation
¶
Index ¶
- func CompareWithHash(HashedString string, Password string) bool
- func CreateHash(Password string) (string, error)
- func CreateHashWithCost(Password string, cost int) (string, error)
- func Decrypt(encryptedData models.EncryptReturnType) (interface{}, error)
- func DecryptBytes(encryptedData models.EncryptReturnType) ([]byte, error)
- func DecryptString(encryptedData models.EncryptReturnType) (string, error)
- func Encrypt(data interface{}) (*models.EncryptReturnType, error)
- func EncryptBytes(data []byte) (*models.EncryptReturnType, error)
- func EncryptString(data string) (*models.EncryptReturnType, error)
- func GenerateEncryptionKey(keySize int) (string, error)
- func GenerateIV() (string, error)
- func GenerateRefreshToken() (string, error)
- func GetHashInfo(hashedString string) (cost int, err error)
- func GetRecommendedCost() int
- func GetSupportedEncryptionTypes() []string
- func GetSupportedKeySizes() []int
- func HashAndVerify(Password string) (string, error)
- func HashToken(token string) string
- func IsHashValid(hashedString string) bool
- func NeedsRehash(hashedString string, minCost int) (bool, error)
- func ValidateEncryptionKey(key string) error
- func ValidateIV(iv string) error
- func ValidateTokenHash(token, hash string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareWithHash ¶
CompareWithHash verifies a plain text password against a bcrypt hash. Returns true if the password matches the hash, false otherwise.
func CreateHash ¶
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
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
GenerateEncryptionKey generates a cryptographically secure random encryption key.
func GenerateIV ¶ added in v1.3.7
GenerateIV generates a cryptographically secure random initialization vector.
func GenerateRefreshToken ¶ added in v1.4.1
GenerateRefreshToken generates a cryptographically secure random token
func GetHashInfo ¶ added in v1.3.7
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
HashAndVerify generates a hash and immediately verifies it against the original password. This is useful for ensuring the hash was generated correctly.
func IsHashValid ¶ added in v1.3.7
IsHashValid checks if a string appears to be a valid bcrypt hash.
func NeedsRehash ¶ added in v1.3.7
NeedsRehash checks if a hash needs to be rehashed with a higher cost factor.
func ValidateEncryptionKey ¶ added in v1.3.7
ValidateEncryptionKey validates if a key is suitable for AES encryption.
func ValidateIV ¶ added in v1.3.7
ValidateIV validates if an initialization vector is suitable for AES encryption.
func ValidateTokenHash ¶ added in v1.4.1
ValidateTokenHash compares a token with its hash
Types ¶
This section is empty.