Documentation ¶
Index ¶
- Variables
- func DecodeString(data string, encodedType Encode) (dst []byte, err error)
- func EncodeToString(data []byte, encodeType Encode) (dst string, err error)
- func GenRsaKey(bits int) (string, string, error)
- func Hash(src string, mode HashMode) (dst []byte)
- func HashToString(src string, mode HashMode, encode Encode) (dst string, err error)
- func HmacSHA256(key []byte, src string) (dst []byte)
- func HmacSHA256ToString(key []byte, src string, encode Encode) (dst string, err error)
- func ParsePrivateKey(path string) (*rsa.PrivateKey, error)
- func ParsePublicKey(path string) (*rsa.PublicKey, error)
- type Aes
- type AesCbcCrypto
- func (acc *AesCbcCrypto) Decrypt(src []byte, ivs ...[]byte) (dst []byte, err error)
- func (acc *AesCbcCrypto) DecryptFromString(src string, mode Encode, ivs ...[]byte) (dst []byte, err error)
- func (acc *AesCbcCrypto) Encrypt(src []byte, ivs ...[]byte) (dst []byte, err error)
- func (acc *AesCbcCrypto) EncryptToString(src []byte, mode Encode, ivs ...[]byte) (dst string, err error)
- type Encode
- type HashMode
- type RsaConfig
- type RsaCrypt
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPaddingSize indicates bad padding size ErrPaddingSize = errors.New("padding size error") // ErrNotFullPadding indicates bad padding size ErrNotFullPadding = errors.New("need a multiple of the block size") )
var ( // ErrPrivateKey indicates the invalid private key. ErrPrivateKey = errors.New("failed to parse private PEM block containing the key") // ErrPublicKey indicates the invalid public key. ErrPublicKey = errors.New("failed to parse public PEM block containing the key") // ErrNotRsaKey indicates the invalid RSA key. ErrNotRsaKey = errors.New("key type is not RSA") )
var ErrInvalidEncodeMode = errors.New("unsupported encode mode")
ErrInvalidEncodeMode unsupported encode mode
Functions ¶
func DecodeString ¶
DecodeString decodes string data to bytes in designed encoded type
func EncodeToString ¶
EncodeToString encodes data to string with encode type
func HashToString ¶
HashToString hash input to assigned encode mode.
func HmacSHA256 ¶
HmacSHA256 returns HMAC bytes for src with the given key
func HmacSHA256ToString ¶
HmacSHA256ToString returns hmac hash string with the given key and assigned encode mode hash mode: md5, sha1, sha256, sha512, default md5
func ParsePrivateKey ¶ added in v1.3.5
func ParsePrivateKey(path string) (*rsa.PrivateKey, error)
ParsePrivateKey parses private key bytes to rsa PrivateKey
Types ¶
type Aes ¶
type Aes interface { Encrypt(src []byte, ivs ...[]byte) (dst []byte, err error) EncryptToString(src []byte, mode Encode, ivs ...[]byte) (dst string, err error) Decrypt(src []byte, ivs ...[]byte) (dst []byte, err error) DecryptFromString(src string, mode Encode, ivs ...[]byte) (dst []byte, err error) }
Aes aes crypt interface definition
type AesCbcCrypto ¶
type AesCbcCrypto struct {
// contains filtered or unexported fields
}
AesCbcCrypt aes cbc mode
func NewAesCbcCrypto ¶
func NewAesCbcCrypto(secret string, iv ...byte) (*AesCbcCrypto, error)
NewAesCbcCrypto returns a aes cbc mode crypto
func (*AesCbcCrypto) Decrypt ¶
func (acc *AesCbcCrypto) Decrypt(src []byte, ivs ...[]byte) (dst []byte, err error)
Decrypt decrypt input slice using assigned ivs
func (*AesCbcCrypto) DecryptFromString ¶
func (acc *AesCbcCrypto) DecryptFromString(src string, mode Encode, ivs ...[]byte) (dst []byte, err error)
DecryptFromString decrypt input string using assigned encode mode encode mode: Base64,HEX or Plain String
func (*AesCbcCrypto) Encrypt ¶
func (acc *AesCbcCrypto) Encrypt(src []byte, ivs ...[]byte) (dst []byte, err error)
Encrypt encrypt input slice using assigned ivs
func (*AesCbcCrypto) EncryptToString ¶
func (acc *AesCbcCrypto) EncryptToString(src []byte, mode Encode, ivs ...[]byte) (dst string, err error)
EncryptToString encrypt input slice using assigned ivs and return encode encrypt string encode mode: Base64,HEX or Plain String
type RsaCrypt ¶
type RsaCrypt struct {
// contains filtered or unexported fields
}
func NewRsaCrypt ¶
NewRsaCrypt init with the RSA config
func (*RsaCrypt) Decrypt ¶
Decrypt decrypts input slice using private key and return byte slice src the encrypted data with public key
func (*RsaCrypt) DecryptFromString ¶
DecryptFromString decrypts a plaintext using private key and return string src the encrypted data with public key mode the encode type of encrypted data,such as Base64,HEX or Plain String