Documentation ¶
Index ¶
- Constants
- Variables
- func FixedKeyByRepeatContent(keyLen int, key []byte) []byte
- func FixedKeyByWhitespacePrefix(keyLen int, key []byte) []byte
- func FixedKeyDefault(keyLen int, key []byte) []byte
- func GenDESKey(key []byte) []byte
- func Md5bytes(v []byte) []byte
- func Md5str(v string) string
- func NewECBDecrypter(b cipher.Block) cipher.BlockMode
- func NewECBEncrypter(b cipher.Block) cipher.BlockMode
- func PKCS5Padding(ciphertext []byte, blockSize int) []byte
- func PKCS5UnPadding(origData []byte) []byte
- func PKCS7Padding(ciphertext []byte, blockSize int) []byte
- func PKCS7UnPadding(origData []byte) []byte
- func ZeroPadding(ciphertext []byte, blockSize int) []byte
- func ZeroUnPadding(origData []byte) []byte
- type AES
- type AESCBC
- func (c *AESCBC) Decode(cryptedData, authKey string) string
- func (c *AESCBC) DecodeBytes(cryptedData, authKey []byte) []byte
- func (c *AESCBC) Encode(rawData, authKey string) string
- func (c *AESCBC) EncodeBytes(rawData, authKey []byte) []byte
- func (a AESCBC) GenKey(key []byte, typ ...string) []byte
- func (a AESCBC) GetKey(key []byte) []byte
- func (a AESCBC) SetKeyFixer(fixer KeyFixer)
- type AESECB
- func (c *AESECB) Decode(cryptedData, authKey string) string
- func (c *AESECB) DecodeBytes(cryptedData, authKey []byte) []byte
- func (c *AESECB) Encode(rawData, authKey string) string
- func (c *AESECB) EncodeBytes(rawData, authKey []byte) []byte
- func (a AESECB) GenKey(key []byte, typ ...string) []byte
- func (a AESECB) GetKey(key []byte) []byte
- func (a AESECB) SetKeyFixer(fixer KeyFixer)
- type Codec
- type DESCBC
- func (d *DESCBC) Decode(cryptedStr, secret string) string
- func (d *DESCBC) DecodeBytes(crypted, secret []byte) []byte
- func (d *DESCBC) Encode(text, secret string) string
- func (d *DESCBC) EncodeBytes(text, secret []byte) []byte
- func (d *DESCBC) GenKey(key []byte) []byte
- func (a DESCBC) GetKey(key []byte) []byte
- func (a DESCBC) SetKeyFixer(fixer KeyFixer)
- type DESECB
- func (d *DESECB) Decode(crypted, secret string) string
- func (d *DESECB) DecodeBytes(crypted, secret []byte) []byte
- func (d *DESECB) Encode(text, secret string) string
- func (d *DESECB) EncodeBytes(text, secret []byte) []byte
- func (d *DESECB) GenKey(key []byte) []byte
- func (a DESECB) GetKey(key []byte) []byte
- func (a DESECB) SetKeyFixer(fixer KeyFixer)
- type KeyFixer
- type RSA
- func (r *RSA) PrivateKey() *RSAPrivateKey
- func (r *RSA) PublicKey() *RSAPublicKey
- func (r *RSA) SetPrivateKey(privateKey *RSAPrivateKey) *RSA
- func (r *RSA) SetPrivateKeyBytes(privateKey []byte) (err error)
- func (r *RSA) SetPublicKey(publicKey *RSAPublicKey) *RSA
- func (r *RSA) SetPublicKeyBytes(publicKey []byte) (err error)
- type RSAPrivateKey
- func (r *RSAPrivateKey) Decrypt(input []byte) ([]byte, error)
- func (rsas *RSAPrivateKey) Encrypt(input []byte) ([]byte, error)
- func (r *RSAPrivateKey) GetPrivateKey() (*rsa.PrivateKey, error)
- func (r *RSAPrivateKey) SetPrivateKey(privateKey *rsa.PrivateKey) *RSAPrivateKey
- func (r *RSAPrivateKey) SetPrivateKeyBytes(privateKey []byte) error
- func (r *RSAPrivateKey) SignMd5(data []byte) ([]byte, error)
- func (r *RSAPrivateKey) SignSha1(data []byte) ([]byte, error)
- func (r *RSAPrivateKey) SignSha256(data []byte) ([]byte, error)
- type RSAPublicKey
- func (r *RSAPublicKey) Decrypt(input []byte) ([]byte, error)
- func (r *RSAPublicKey) Encrypt(input []byte) ([]byte, error)
- func (r *RSAPublicKey) GetPublicKey() (*rsa.PublicKey, error)
- func (r *RSAPublicKey) SetPublicKey(publicKey *rsa.PublicKey) *RSAPublicKey
- func (r *RSAPublicKey) SetPublicKeyBytes(publicKey []byte) error
- func (r *RSAPublicKey) VerifySignMd5(data string, signData string) error
- func (r *RSAPublicKey) VerifySignSha1(data []byte, sign []byte) error
- func (r *RSAPublicKey) VerifySignSha256(data []byte, sign []byte) error
- type SafeKeys
Constants ¶
View Source
const ( AlgoAES128CBC = `AES-128-CBC` AlgoAES192CBC = `AES-192-CBC` AlgoAES256CBC = `AES-256-CBC` AlgoAES128ECB = `AES-128-ECB` AlgoAES192ECB = `AES-192-ECB` AlgoAES256ECB = `AES-256-ECB` )
View Source
const ( KeyAES128 = `AES-128` KeyAES192 = `AES-192` KeyAES256 = `AES-256` )
Variables ¶
View Source
var ( ErrDataTooLarge = errors.New("message too long for RSA public key size") ErrDataLength = errors.New("data length error") ErrDataBroken = errors.New("data broken, first byte is not zero") ErrKeyPairDismatch = errors.New("data is not encrypted by the private key") ErrDecryption = errors.New("decryption error") ErrPublicKey = errors.New("get public key error") ErrPrivateKey = errors.New("get private key error") ErrPublicKeyNotSet = errors.New(`please set the public key in advance`) ErrPrivateKeyNotSet = errors.New(`please set the private key in advance`) )
View Source
var AESKeyTypes = map[string]int{ KeyAES128: aes128KeyLen, KeyAES192: aes192KeyLen, KeyAES256: aes256KeyLen, }
AESKeyTypes AES Key类型
View Source
var FixedAESKey = FixedKeyDefault
View Source
var FixedDESKey = FixedKeyByRepeatContent
Functions ¶
func FixedKeyByRepeatContent ¶ added in v0.2.3
func FixedKeyByWhitespacePrefix ¶ added in v0.2.3
func FixedKeyDefault ¶ added in v0.3.0
func NewECBDecrypter ¶
NewECBDecrypter returns a BlockMode which decrypts in electronic code book mode, using the given Block.
func NewECBEncrypter ¶
NewECBEncrypter returns a BlockMode which encrypts in electronic code book mode, using the given Block.
func PKCS5Padding ¶
func PKCS5UnPadding ¶
func PKCS7Padding ¶
func PKCS7UnPadding ¶
func ZeroPadding ¶
func ZeroUnPadding ¶
Types ¶
type AESCBC ¶ added in v0.2.0
type AESCBC struct {
// contains filtered or unexported fields
}
func (*AESCBC) DecodeBytes ¶ added in v0.2.0
func (*AESCBC) EncodeBytes ¶ added in v0.2.0
func (AESCBC) SetKeyFixer ¶ added in v0.3.0
func (a AESCBC) SetKeyFixer(fixer KeyFixer)
type AESECB ¶ added in v0.2.0
type AESECB struct {
// contains filtered or unexported fields
}
func (*AESECB) DecodeBytes ¶ added in v0.2.0
func (*AESECB) EncodeBytes ¶ added in v0.2.0
func (AESECB) SetKeyFixer ¶ added in v0.3.0
func (a AESECB) SetKeyFixer(fixer KeyFixer)
type Codec ¶
type DESCBC ¶ added in v0.2.0
type DESCBC struct {
// contains filtered or unexported fields
}
func (*DESCBC) DecodeBytes ¶ added in v0.2.0
func (*DESCBC) EncodeBytes ¶ added in v0.2.0
func (DESCBC) SetKeyFixer ¶ added in v0.3.0
func (a DESCBC) SetKeyFixer(fixer KeyFixer)
type DESECB ¶ added in v0.2.0
type DESECB struct {
// contains filtered or unexported fields
}
func (*DESECB) DecodeBytes ¶ added in v0.2.0
func (*DESECB) EncodeBytes ¶ added in v0.2.0
func (DESECB) SetKeyFixer ¶ added in v0.3.0
func (a DESECB) SetKeyFixer(fixer KeyFixer)
type RSA ¶ added in v0.0.2
type RSA struct {
// contains filtered or unexported fields
}
func (*RSA) PrivateKey ¶ added in v0.0.2
func (r *RSA) PrivateKey() *RSAPrivateKey
func (*RSA) PublicKey ¶ added in v0.0.2
func (r *RSA) PublicKey() *RSAPublicKey
func (*RSA) SetPrivateKey ¶ added in v0.0.2
func (r *RSA) SetPrivateKey(privateKey *RSAPrivateKey) *RSA
func (*RSA) SetPrivateKeyBytes ¶ added in v0.1.1
func (*RSA) SetPublicKey ¶ added in v0.0.2
func (r *RSA) SetPublicKey(publicKey *RSAPublicKey) *RSA
func (*RSA) SetPublicKeyBytes ¶ added in v0.1.1
type RSAPrivateKey ¶ added in v0.0.2
type RSAPrivateKey struct {
// contains filtered or unexported fields
}
func NewRSAPrivateKey ¶ added in v0.0.2
func NewRSAPrivateKey(privateKey []byte) (r *RSAPrivateKey, err error)
设置私钥
func (*RSAPrivateKey) Decrypt ¶ added in v0.0.2
func (r *RSAPrivateKey) Decrypt(input []byte) ([]byte, error)
私钥解密
func (*RSAPrivateKey) Encrypt ¶ added in v0.0.2
func (rsas *RSAPrivateKey) Encrypt(input []byte) ([]byte, error)
私钥加密
func (*RSAPrivateKey) GetPrivateKey ¶ added in v0.1.0
func (r *RSAPrivateKey) GetPrivateKey() (*rsa.PrivateKey, error)
*rsa.PrivateKey
func (*RSAPrivateKey) SetPrivateKey ¶ added in v0.1.0
func (r *RSAPrivateKey) SetPrivateKey(privateKey *rsa.PrivateKey) *RSAPrivateKey
func (*RSAPrivateKey) SetPrivateKeyBytes ¶ added in v0.1.0
func (r *RSAPrivateKey) SetPrivateKeyBytes(privateKey []byte) error
func (*RSAPrivateKey) SignMd5 ¶ added in v0.0.3
func (r *RSAPrivateKey) SignMd5(data []byte) ([]byte, error)
*
- 使用RSAWithMD5算法签名
func (*RSAPrivateKey) SignSha1 ¶ added in v0.0.3
func (r *RSAPrivateKey) SignSha1(data []byte) ([]byte, error)
*
- 使用RSAWithSHA1算法签名
func (*RSAPrivateKey) SignSha256 ¶ added in v0.0.3
func (r *RSAPrivateKey) SignSha256(data []byte) ([]byte, error)
*
- 使用RSAWithSHA256算法签名
type RSAPublicKey ¶ added in v0.0.2
type RSAPublicKey struct {
// contains filtered or unexported fields
}
func NewRSAPublicKey ¶ added in v0.0.2
func NewRSAPublicKey(publicKey []byte) (r *RSAPublicKey, err error)
设置公钥
func (*RSAPublicKey) Decrypt ¶ added in v0.0.2
func (r *RSAPublicKey) Decrypt(input []byte) ([]byte, error)
公钥解密
func (*RSAPublicKey) Encrypt ¶ added in v0.0.2
func (r *RSAPublicKey) Encrypt(input []byte) ([]byte, error)
公钥加密
func (*RSAPublicKey) GetPublicKey ¶ added in v0.1.0
func (r *RSAPublicKey) GetPublicKey() (*rsa.PublicKey, error)
*rsa.PrivateKey
func (*RSAPublicKey) SetPublicKey ¶ added in v0.1.0
func (r *RSAPublicKey) SetPublicKey(publicKey *rsa.PublicKey) *RSAPublicKey
func (*RSAPublicKey) SetPublicKeyBytes ¶ added in v0.1.0
func (r *RSAPublicKey) SetPublicKeyBytes(publicKey []byte) error
func (*RSAPublicKey) VerifySignMd5 ¶ added in v0.0.3
func (r *RSAPublicKey) VerifySignMd5(data string, signData string) error
*
- 使用RSAWithMD5验证签名
func (*RSAPublicKey) VerifySignSha1 ¶ added in v0.0.3
func (r *RSAPublicKey) VerifySignSha1(data []byte, sign []byte) error
*
- 使用RSAWithSHA1验证签名
func (*RSAPublicKey) VerifySignSha256 ¶ added in v0.0.3
func (r *RSAPublicKey) VerifySignSha256(data []byte, sign []byte) error
*
- 使用RSAWithSHA256验证签名
Click to show internal directories.
Click to hide internal directories.