Documentation
¶
Index ¶
- func AESDecrypt(ciphertext, key []byte) ([]byte, error)
- func AESEncrypt(data, key []byte) ([]byte, error)
- func CheckPassword(password, hash string) bool
- func DecryptString(ciphertext string, key []byte) (string, error)
- func DeriveKey(password, salt []byte, keyLen int) ([]byte, error)
- func EncryptString(plaintext string, key []byte) (string, error)
- func GenerateAPIKey() (string, error)
- func GenerateRSAKeyPair(bits int) (*rsa.PrivateKey, *rsa.PublicKey, error)
- func GenerateRandomBase64(length int) (string, error)
- func GenerateRandomBytes(n int) ([]byte, error)
- func GenerateRandomHex(length int) (string, error)
- func GenerateRandomString(length int) (string, error)
- func GenerateSalt() ([]byte, error)
- func GenerateSecretKey() ([]byte, error)
- func GenerateToken(length int) (string, error)
- func HMACSHA256(data, key []byte) []byte
- func HashPassword(password string) (string, error)
- func HashPasswordSecure(password string) (hash, salt string, err error)
- func HashPasswordWithSalt(password, salt []byte) ([]byte, error)
- func HashSHA256Hex(input string) string
- func RSADecrypt(ciphertext []byte, privateKey *rsa.PrivateKey) ([]byte, error)
- func RSAEncrypt(data []byte, publicKey *rsa.PublicKey) ([]byte, error)
- func RSAPrivateKeyFromPEM(pemData []byte) (*rsa.PrivateKey, error)
- func RSAPrivateKeyToPEM(key *rsa.PrivateKey) ([]byte, error)
- func RSAPublicKeyFromPEM(pemData []byte) (*rsa.PublicKey, error)
- func RSAPublicKeyToPEM(key *rsa.PublicKey) ([]byte, error)
- func RSASign(data []byte, privateKey *rsa.PrivateKey) ([]byte, error)
- func RSAVerify(data, signature []byte, publicKey *rsa.PublicKey) error
- func VerifyHMACSHA256(data, signature, key []byte) bool
- func VerifyPasswordSecure(password, hash, salt string) (bool, error)
- type JWTClaims
- type SimpleJWT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AESDecrypt ¶
AESDecrypt decrypts data using AES-GCM
func AESEncrypt ¶
AESEncrypt encrypts data using AES-GCM
func CheckPassword ¶
CheckPassword compares a password with a hash
func DecryptString ¶
DecryptString decrypts a base64 encoded string using AES-GCM
func EncryptString ¶
EncryptString encrypts a string using AES-GCM and returns base64 encoded result
func GenerateAPIKey ¶
GenerateAPIKey generates a secure API key
func GenerateRSAKeyPair ¶
GenerateRSAKeyPair generates an RSA key pair
func GenerateRandomBase64 ¶
GenerateRandomBase64 generates a random base64 string
func GenerateRandomBytes ¶
GenerateRandomBytes generates cryptographically secure random bytes
func GenerateRandomHex ¶
GenerateRandomHex generates a random hex string of specified length
func GenerateRandomString ¶
GenerateRandomString generates a cryptographically secure random string
func GenerateSalt ¶
GenerateSalt generates a random salt for password hashing
func GenerateSecretKey ¶
GenerateSecretKey generates a secure secret key for encryption
func GenerateToken ¶
GenerateToken generates a secure random token for authentication
func HashPassword ¶
HashPassword creates a bcrypt hash of the password
func HashPasswordSecure ¶
HashPasswordSecure hashes a password with a random salt
func HashPasswordWithSalt ¶
HashPasswordWithSalt hashes a password with a given salt using scrypt
func HashSHA256Hex ¶
HashSHA256Hex returns the hex-encoded SHA-256 hash of the input string.
func RSADecrypt ¶
func RSADecrypt(ciphertext []byte, privateKey *rsa.PrivateKey) ([]byte, error)
RSADecrypt decrypts data using RSA private key
func RSAEncrypt ¶
RSAEncrypt encrypts data using RSA public key
func RSAPrivateKeyFromPEM ¶
func RSAPrivateKeyFromPEM(pemData []byte) (*rsa.PrivateKey, error)
RSAPrivateKeyFromPEM loads an RSA private key from PEM format
func RSAPrivateKeyToPEM ¶
func RSAPrivateKeyToPEM(key *rsa.PrivateKey) ([]byte, error)
RSAPrivateKeyToPEM converts an RSA private key to PEM format
func RSAPublicKeyFromPEM ¶
RSAPublicKeyFromPEM loads an RSA public key from PEM format
func RSAPublicKeyToPEM ¶
RSAPublicKeyToPEM converts an RSA public key to PEM format
func RSASign ¶
func RSASign(data []byte, privateKey *rsa.PrivateKey) ([]byte, error)
RSASign signs data using RSA private key
func VerifyHMACSHA256 ¶
VerifyHMACSHA256 verifies an HMAC-SHA256 signature
func VerifyPasswordSecure ¶
VerifyPasswordSecure verifies a password against a hash and salt
Types ¶
type JWTClaims ¶
type JWTClaims struct {
Issuer string `json:"iss,omitempty"`
Subject string `json:"sub,omitempty"`
Audience string `json:"aud,omitempty"`
ExpiresAt int64 `json:"exp,omitempty"`
NotBefore int64 `json:"nbf,omitempty"`
IssuedAt int64 `json:"iat,omitempty"`
ID string `json:"jti,omitempty"`
Custom map[string]interface{} `json:"-"`
}
JWTClaims represents JWT claims
type SimpleJWT ¶
type SimpleJWT struct {
SecretKey []byte
}
SimpleJWT represents a simple JWT implementation
func NewSimpleJWT ¶
NewSimpleJWT creates a new SimpleJWT instance
func (*SimpleJWT) CreateToken ¶
CreateToken creates a JWT token with the given claims