Documentation
¶
Overview ¶
Package cryptoutil provides utility functions for encryption, decryption, and hashing.
Index ¶
- Constants
- func AESDecrypt(encryptedData, key []byte) ([]byte, error)
- func AESDecryptString(encryptedData, key string) (string, error)
- func AESEncrypt(data, key []byte) ([]byte, error)
- func AESEncryptString(data, key string) (string, error)
- func Base64Decode(s string) ([]byte, error)
- func Base64Encode(data []byte) string
- func Base64URLDecode(s string) ([]byte, error)
- func Base64URLEncode(data []byte) string
- func DESDecrypt(encryptedData, key []byte) ([]byte, error)
- func DESDecryptHex(encryptedHex, key string) (string, error)
- func DESDecryptString(encryptedData, key string) (string, error)
- func DESDecryptWithFixedIV(encryptedData, key []byte) ([]byte, error)
- func DESEncrypt(data, key []byte) ([]byte, error)
- func DESEncryptHex(data, key string) (string, error)
- func DESEncryptString(data, key string) (string, error)
- func DESEncryptWithFixedIV(data, key []byte) ([]byte, error)
- func GenerateRandomBytes(length int) ([]byte, error)
- func GenerateRandomString(length int, encoding string) (string, error)
- func HMAC(data, key []byte, algorithm string) (string, error)
- func HMACString(data, key, algorithm string) (string, error)
- func Hash(data []byte, algorithm string) (string, error)
- func HashString(s, algorithm string) (string, error)
- func HexDecode(s string) ([]byte, error)
- func HexEncode(data []byte) string
- func MD5Hash(data []byte) string
- func MD5String(s string) string
- func PKCS7Pad(data []byte, blockSize int) []byte
- func PKCS7Unpad(data []byte) ([]byte, error)
- func ParsePrivateKeyFromPEM(pemData []byte) (*rsa.PrivateKey, error)
- func ParsePublicKeyFromPEM(pemData []byte) (*rsa.PublicKey, error)
- func RSADecrypt(encryptedData []byte, privateKey *rsa.PrivateKey) ([]byte, error)
- func RSAEncrypt(data []byte, publicKey *rsa.PublicKey) ([]byte, error)
- func RSASign(data []byte, privateKey *rsa.PrivateKey) ([]byte, error)
- func RSAVerify(data, signature []byte, publicKey *rsa.PublicKey) error
- func SHA1Hash(data []byte) string
- func SHA1String(s string) string
- func SHA256Hash(data []byte) string
- func SHA256String(s string) string
- func SHA512Hash(data []byte) string
- func SHA512String(s string) string
- func SimpleDecrypt(encryptedData, password string) (string, error)
- func SimpleEncrypt(data, password string) (string, error)
- func TripleDESDecrypt(encryptedData, key []byte) ([]byte, error)
- func TripleDESDecryptString(encryptedData, key string) (string, error)
- func TripleDESEncrypt(data, key []byte) ([]byte, error)
- func TripleDESEncryptString(data, key string) (string, error)
- func VerifyHMAC(data, key []byte, signature, algorithm string) (bool, error)
- func VerifyHMACString(data, key, signature, algorithm string) (bool, error)
- type RSAKeyPair
Constants ¶
const ( MD5 = "md5" SHA1 = "sha1" SHA256 = "sha256" SHA512 = "sha512" )
Hash algorithms
const ( HexEncoding = "hex" Base64Encoding = "base64" )
Encoding types
Variables ¶
This section is empty.
Functions ¶
func AESDecrypt ¶
AESDecrypt decrypts data using AES with the given key
func AESDecryptString ¶
AESDecryptString decrypts base64 encoded string using AES
func AESEncrypt ¶
AESEncrypt encrypts data using AES with the given key
func AESEncryptString ¶
AESEncryptString encrypts string using AES
func Base64Decode ¶
Base64Decode decodes base64 string to data
func Base64Encode ¶
Base64Encode encodes data to base64 string
func Base64URLDecode ¶
Base64URLDecode decodes URL-safe base64 string to data
func Base64URLEncode ¶
Base64URLEncode encodes data to URL-safe base64 string
func DESDecrypt ¶
DESDecrypt decrypts data using DES with the given key (8 bytes)
func DESDecryptHex ¶
DESDecryptHex decrypts hex encoded string using DES with fixed IV - compatible with your code
func DESDecryptString ¶
DESDecryptString decrypts base64 encoded string using DES
func DESDecryptWithFixedIV ¶
DESDecryptWithFixedIV decrypts data using DES with fixed IV (key as IV) - compatible mode
func DESEncrypt ¶
DESEncrypt encrypts data using DES with the given key (8 bytes)
func DESEncryptHex ¶
DESEncryptHex encrypts string using DES with fixed IV and returns hex string - compatible with your code
func DESEncryptString ¶
DESEncryptString encrypts string using DES
func DESEncryptWithFixedIV ¶
DESEncryptWithFixedIV encrypts data using DES with fixed IV (key as IV) - compatible mode
func GenerateRandomBytes ¶
GenerateRandomBytes generates random bytes of specified length
func GenerateRandomString ¶
GenerateRandomString generates random string of specified length
func HMACString ¶
HMACString generates HMAC for string data
func HashString ¶
HashString returns hash of the input string using the specified algorithm
func PKCS7Unpad ¶
PKCS7Unpad removes PKCS7 padding from data
func ParsePrivateKeyFromPEM ¶
func ParsePrivateKeyFromPEM(pemData []byte) (*rsa.PrivateKey, error)
ParsePrivateKeyFromPEM parses private key from PEM format
func ParsePublicKeyFromPEM ¶
ParsePublicKeyFromPEM parses public key from PEM format
func RSADecrypt ¶
func RSADecrypt(encryptedData []byte, privateKey *rsa.PrivateKey) ([]byte, error)
RSADecrypt decrypts data using RSA private key
func RSAEncrypt ¶
RSAEncrypt encrypts data using RSA public key
func RSASign ¶
func RSASign(data []byte, privateKey *rsa.PrivateKey) ([]byte, error)
RSASign signs data using RSA private key with SHA256
func SHA256Hash ¶
SHA256Hash returns SHA256 hash of the input data
func SHA256String ¶
SHA256String returns SHA256 hash of the input string
func SHA512Hash ¶
SHA512Hash returns SHA512 hash of the input data
func SHA512String ¶
SHA512String returns SHA512 hash of the input string
func SimpleDecrypt ¶
SimpleDecrypt provides a simple decryption interface using AES-256
func SimpleEncrypt ¶
SimpleEncrypt provides a simple encryption interface using AES-256
func TripleDESDecrypt ¶
TripleDESDecrypt decrypts data using 3DES with the given key (24 bytes)
func TripleDESDecryptString ¶
TripleDESDecryptString decrypts base64 encoded string using 3DES
func TripleDESEncrypt ¶
TripleDESEncrypt encrypts data using 3DES with the given key (24 bytes)
func TripleDESEncryptString ¶
TripleDESEncryptString encrypts string using 3DES
func VerifyHMAC ¶
VerifyHMAC verifies HMAC signature
func VerifyHMACString ¶
VerifyHMACString verifies HMAC signature for string data
Types ¶
type RSAKeyPair ¶
type RSAKeyPair struct {
PrivateKey *rsa.PrivateKey
PublicKey *rsa.PublicKey
}
RSAKeyPair represents an RSA key pair
func GenerateRSAKeyPair ¶
func GenerateRSAKeyPair(bits int) (*RSAKeyPair, error)
GenerateRSAKeyPair generates a new RSA key pair
func (*RSAKeyPair) PrivateKeyToPEM ¶
func (kp *RSAKeyPair) PrivateKeyToPEM() ([]byte, error)
PrivateKeyToPEM converts private key to PEM format
func (*RSAKeyPair) PublicKeyToPEM ¶
func (kp *RSAKeyPair) PublicKeyToPEM() ([]byte, error)
PublicKeyToPEM converts public key to PEM format