Documentation ¶
Overview ¶
Package cryptor implements some util functions to encrypt and decrypt. Contain base64, hmac, sha, aes, des, and rsa
Package cryptor implements some util functions to encrypt and decrypt. Note: 1. for aes crypt function, the `key` param length should be 16, 24 or 32. if not, will panic.
Index ¶
- func AesCbcDecrypt(encrypted, key []byte) []byte
- func AesCbcEncrypt(data, key []byte) []byte
- func AesCfbDecrypt(encrypted, key []byte) []byte
- func AesCfbEncrypt(data, key []byte) []byte
- func AesCtrCrypt(data, key []byte) []byte
- func AesEcbDecrypt(encrypted, key []byte) []byte
- func AesEcbEncrypt(data, key []byte) []byte
- func AesOfbDecrypt(data, key []byte) []byte
- func AesOfbEncrypt(data, key []byte) []byte
- func Base64StdDecode(s string) string
- func Base64StdEncode(s string) string
- func DesCbcDecrypt(encrypted, key []byte) []byte
- func DesCbcEncrypt(data, key []byte) []byte
- func DesCfbDecrypt(encrypted, key []byte) []byte
- func DesCfbEncrypt(data, key []byte) []byte
- func DesCtrCrypt(data, key []byte) []byte
- func DesEcbDecrypt(encrypted, key []byte) []byte
- func DesEcbEncrypt(data, key []byte) []byte
- func DesOfbDecrypt(data, key []byte) []byte
- func DesOfbEncrypt(data, key []byte) []byte
- func GenerateRsaKey(keySize int, priKeyFile, pubKeyFile string) error
- func GenerateRsaKeyPair(keySize int) (*rsa.PrivateKey, *rsa.PublicKey)
- func HmacMd5(data, key string) string
- func HmacMd5WithBase64(data, key string) string
- func HmacSha1(data, key string) string
- func HmacSha1WithBase64(str, key string) string
- func HmacSha256(data, key string) string
- func HmacSha256WithBase64(str, key string) string
- func HmacSha512(data, key string) string
- func HmacSha512WithBase64(str, key string) string
- func Md5Byte(data []byte) string
- func Md5ByteWithBase64(data []byte) string
- func Md5File(filename string) (string, error)
- func Md5String(s string) string
- func Md5StringWithBase64(s string) string
- func RsaDecrypt(data []byte, privateKeyFileName string) []byte
- func RsaDecryptOAEP(ciphertext []byte, label []byte, key rsa.PrivateKey) ([]byte, error)
- func RsaEncrypt(data []byte, pubKeyFileName string) []byte
- func RsaEncryptOAEP(data []byte, label []byte, key rsa.PublicKey) ([]byte, error)
- func Sha1(data string) string
- func Sha1WithBase64(str string) string
- func Sha256(data string) string
- func Sha256WithBase64(str string) string
- func Sha512(data string) string
- func Sha512WithBase64(str string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AesCbcDecrypt ¶
AesCbcDecrypt decrypt data with key use AES CBC algorithm len(key) should be 16, 24 or 32
func AesCbcEncrypt ¶
AesCbcEncrypt encrypt data with key use AES CBC algorithm len(key) should be 16, 24 or 32
func AesCfbDecrypt ¶
AesCfbDecrypt decrypt data with key use AES CFB algorithm len(encrypted) should be great than 16, len(key) should be 16, 24 or 32
func AesCfbEncrypt ¶
AesCfbEncrypt encrypt data with key use AES CFB algorithm len(key) should be 16, 24 or 32
func AesCtrCrypt ¶
AesCtrCrypt encrypt data with key use AES CTR algorithm len(key) should be 16, 24 or 32
func AesEcbDecrypt ¶
AesEcbDecrypt decrypt data with key use AES ECB algorithm len(key) should be 16, 24 or 32
func AesEcbEncrypt ¶
AesEcbEncrypt encrypt data with key use AES ECB algorithm len(key) should be 16, 24 or 32
func AesOfbDecrypt ¶
AesOfbDecrypt decrypt data with key use AES OFB algorithm len(key) should be 16, 24 or 32
func AesOfbEncrypt ¶
AesOfbEncrypt encrypt data with key use AES OFB algorithm len(key) should be 16, 24 or 32
func Base64StdDecode ¶
Base64StdDecode decode a base64 encoded string
func Base64StdEncode ¶
Base64StdEncode encode string with base64 encoding
func DesCbcDecrypt ¶
DesCbcDecrypt decrypt data with key use DES CBC algorithm len(key) should be 8
func DesCbcEncrypt ¶
DesCbcEncrypt encrypt data with key use DES CBC algorithm len(key) should be 8
func DesCfbDecrypt ¶
DesCfbDecrypt decrypt data with key use DES CFB algorithm len(encrypted) should be great than 16, len(key) should be 8
func DesCfbEncrypt ¶
DesCfbEncrypt encrypt data with key use DES CFB algorithm len(key) should be 8
func DesCtrCrypt ¶
DesCtrCrypt encrypt data with key use DES CTR algorithm len(key) should be 8
func DesEcbDecrypt ¶
DesEcbDecrypt decrypt data with key use DES ECB algorithm len(key) should be 8
func DesEcbEncrypt ¶
DesEcbEncrypt encrypt data with key use DES ECB algorithm len(key) should be 8
func DesOfbDecrypt ¶
DesOfbDecrypt decrypt data with key use DES OFB algorithm len(key) should be 8
func DesOfbEncrypt ¶
DesOfbEncrypt encrypt data with key use DES OFB algorithm len(key) should be 16, 24 or 32
func GenerateRsaKey ¶
GenerateRsaKey make a rsa private key, and return key file name Generated key file is `rsa_private.pem` and `rsa_public.pem` in current path
func GenerateRsaKeyPair ¶ added in v1.4.2
func GenerateRsaKeyPair(keySize int) (*rsa.PrivateKey, *rsa.PublicKey)
GenerateRsaKeyPair create rsa private and public key.
func HmacMd5WithBase64 ¶ added in v1.4.1
HmacMd5WithBase64 return the hmac hash of string use md5 with base64.
func HmacSha1WithBase64 ¶ added in v1.4.1
HmacSha1WithBase64 return the hmac hash of string use sha1 with base64.
func HmacSha256 ¶
HmacSha256 return the hmac hash of string use sha256
func HmacSha256WithBase64 ¶ added in v1.4.1
HmacSha256WithBase64 return the hmac hash of string use sha256 with base64.
func HmacSha512 ¶
HmacSha512 return the hmac hash of string use sha512
func HmacSha512WithBase64 ¶ added in v1.4.1
HmacSha512WithBase64 return the hmac hash of string use sha512 with base64.
func Md5ByteWithBase64 ¶ added in v1.4.1
Md5ByteWithBase64 return the md5 string of byte slice with base64.
func Md5StringWithBase64 ¶ added in v1.4.1
Md5StringWithBase64 return the md5 value of string with base64.
func RsaDecrypt ¶
RsaDecrypt decrypt data with ras algorithm
func RsaDecryptOAEP ¶ added in v1.4.2
RsaDecryptOAEP decrypts the data with RSA-OAEP.
func RsaEncrypt ¶
RsaEncrypt encrypt data with ras algorithm
func RsaEncryptOAEP ¶ added in v1.4.2
RsaEncryptOAEP encrypts the given data with RSA-OAEP.
func Sha1WithBase64 ¶ added in v1.4.1
Sha1WithBase64 return the sha1 value (SHA-1 hash algorithm) of base64 string.
func Sha256WithBase64 ¶ added in v1.4.1
Sha256WithBase64 return the sha256 value (SHA256 hash algorithm) of base64 string.
func Sha512WithBase64 ¶ added in v1.4.1
Sha512WithBase64 return the sha512 value (SHA512 hash algorithm) of base64 string.
Types ¶
This section is empty.