cryptor

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 19 Imported by: 1

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AesCbcDecrypt

func AesCbcDecrypt(encrypted, key []byte) []byte

AesCbcDecrypt decrypt data with key use AES CBC algorithm len(key) should be 16, 24 or 32

func AesCbcEncrypt

func AesCbcEncrypt(data, key []byte) []byte

AesCbcEncrypt encrypt data with key use AES CBC algorithm len(key) should be 16, 24 or 32

func AesCfbDecrypt

func AesCfbDecrypt(encrypted, key []byte) []byte

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

func AesCfbEncrypt(data, key []byte) []byte

AesCfbEncrypt encrypt data with key use AES CFB algorithm len(key) should be 16, 24 or 32

func AesCtrCrypt

func AesCtrCrypt(data, key []byte) []byte

AesCtrCrypt encrypt data with key use AES CTR algorithm len(key) should be 16, 24 or 32

func AesEcbDecrypt

func AesEcbDecrypt(encrypted, key []byte) []byte

AesEcbDecrypt decrypt data with key use AES ECB algorithm len(key) should be 16, 24 or 32

func AesEcbEncrypt

func AesEcbEncrypt(data, key []byte) []byte

AesEcbEncrypt encrypt data with key use AES ECB algorithm len(key) should be 16, 24 or 32

func AesOfbDecrypt

func AesOfbDecrypt(data, key []byte) []byte

AesOfbDecrypt decrypt data with key use AES OFB algorithm len(key) should be 16, 24 or 32

func AesOfbEncrypt

func AesOfbEncrypt(data, key []byte) []byte

AesOfbEncrypt encrypt data with key use AES OFB algorithm len(key) should be 16, 24 or 32

func Base64StdDecode

func Base64StdDecode(s string) string

Base64StdDecode decode a base64 encoded string

func Base64StdEncode

func Base64StdEncode(s string) string

Base64StdEncode encode string with base64 encoding

func DesCbcDecrypt

func DesCbcDecrypt(encrypted, key []byte) []byte

DesCbcDecrypt decrypt data with key use DES CBC algorithm len(key) should be 8

func DesCbcEncrypt

func DesCbcEncrypt(data, key []byte) []byte

DesCbcEncrypt encrypt data with key use DES CBC algorithm len(key) should be 8

func DesCfbDecrypt

func DesCfbDecrypt(encrypted, key []byte) []byte

DesCfbDecrypt decrypt data with key use DES CFB algorithm len(encrypted) should be great than 16, len(key) should be 8

func DesCfbEncrypt

func DesCfbEncrypt(data, key []byte) []byte

DesCfbEncrypt encrypt data with key use DES CFB algorithm len(key) should be 8

func DesCtrCrypt

func DesCtrCrypt(data, key []byte) []byte

DesCtrCrypt encrypt data with key use DES CTR algorithm len(key) should be 8

func DesEcbDecrypt

func DesEcbDecrypt(encrypted, key []byte) []byte

DesEcbDecrypt decrypt data with key use DES ECB algorithm len(key) should be 8

func DesEcbEncrypt

func DesEcbEncrypt(data, key []byte) []byte

DesEcbEncrypt encrypt data with key use DES ECB algorithm len(key) should be 8

func DesOfbDecrypt

func DesOfbDecrypt(data, key []byte) []byte

DesOfbDecrypt decrypt data with key use DES OFB algorithm len(key) should be 8

func DesOfbEncrypt

func DesOfbEncrypt(data, key []byte) []byte

DesOfbEncrypt encrypt data with key use DES OFB algorithm len(key) should be 16, 24 or 32

func GenerateRsaKey

func GenerateRsaKey(keySize int, priKeyFile, pubKeyFile string) error

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 HmacMd5

func HmacMd5(data, key string) string

HmacMd5 return the hmac hash of string use md5

func HmacMd5WithBase64 added in v1.4.1

func HmacMd5WithBase64(data, key string) string

HmacMd5WithBase64 return the hmac hash of string use md5 with base64.

func HmacSha1

func HmacSha1(data, key string) string

HmacSha1 return the hmac hash of string use sha1

func HmacSha1WithBase64 added in v1.4.1

func HmacSha1WithBase64(str, key string) string

HmacSha1WithBase64 return the hmac hash of string use sha1 with base64.

func HmacSha256

func HmacSha256(data, key string) string

HmacSha256 return the hmac hash of string use sha256

func HmacSha256WithBase64 added in v1.4.1

func HmacSha256WithBase64(str, key string) string

HmacSha256WithBase64 return the hmac hash of string use sha256 with base64.

func HmacSha512

func HmacSha512(data, key string) string

HmacSha512 return the hmac hash of string use sha512

func HmacSha512WithBase64 added in v1.4.1

func HmacSha512WithBase64(str, key string) string

HmacSha512WithBase64 return the hmac hash of string use sha512 with base64.

func Md5Byte added in v1.4.1

func Md5Byte(data []byte) string

Md5Byte return the md5 string of byte slice.

func Md5ByteWithBase64 added in v1.4.1

func Md5ByteWithBase64(data []byte) string

Md5ByteWithBase64 return the md5 string of byte slice with base64.

func Md5File

func Md5File(filename string) (string, error)

Md5File return the md5 value of file

func Md5String

func Md5String(s string) string

Md5String return the md5 value of string

func Md5StringWithBase64 added in v1.4.1

func Md5StringWithBase64(s string) string

Md5StringWithBase64 return the md5 value of string with base64.

func RsaDecrypt

func RsaDecrypt(data []byte, privateKeyFileName string) []byte

RsaDecrypt decrypt data with ras algorithm

func RsaDecryptOAEP added in v1.4.2

func RsaDecryptOAEP(ciphertext []byte, label []byte, key rsa.PrivateKey) ([]byte, error)

RsaDecryptOAEP decrypts the data with RSA-OAEP.

func RsaEncrypt

func RsaEncrypt(data []byte, pubKeyFileName string) []byte

RsaEncrypt encrypt data with ras algorithm

func RsaEncryptOAEP added in v1.4.2

func RsaEncryptOAEP(data []byte, label []byte, key rsa.PublicKey) ([]byte, error)

RsaEncryptOAEP encrypts the given data with RSA-OAEP.

func Sha1

func Sha1(data string) string

Sha1 return the sha1 value (SHA-1 hash algorithm) of string

func Sha1WithBase64 added in v1.4.1

func Sha1WithBase64(str string) string

Sha1WithBase64 return the sha1 value (SHA-1 hash algorithm) of base64 string.

func Sha256

func Sha256(data string) string

Sha256 return the sha256 value (SHA256 hash algorithm) of string

func Sha256WithBase64 added in v1.4.1

func Sha256WithBase64(str string) string

Sha256WithBase64 return the sha256 value (SHA256 hash algorithm) of base64 string.

func Sha512

func Sha512(data string) string

Sha512 return the sha512 value (SHA512 hash algorithm) of string

func Sha512WithBase64 added in v1.4.1

func Sha512WithBase64(str string) string

Sha512WithBase64 return the sha512 value (SHA512 hash algorithm) of base64 string.

Types

This section is empty.

Jump to

Keyboard shortcuts

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