Documentation
¶
Index ¶
Constants ¶
View Source
const ( PaddingTypeNoPadding paddingType = iota //接口不对数据进行填充处理,需要自己手动填充(加解密双方自行定义填充方式) PaddingTypePKCS5 //PKCS5 PaddingTypePKCS7 //PKCS7 PaddingTypeZeros //用0作为填充 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cipher ¶
type Cipher interface { //RC4 //加密,返回[]byte RC4EncryptToBytes(data interface{}, key []byte) ([]byte, error) //加密,返回base64 string RC4EncryptToString(data interface{}, key []byte) (string, error) //解密[]byte RC4Decrypt(encryptData interface{}, key []byte) ([]byte, error) //AES/DES/3DES //加密,返回[]byte SymEncryptToBytes(request *SymRequest) (encryptData []byte, err error) //加密,返回base64 string SymEncryptToString(request *SymRequest) (encryptString string, err error) //解密[]byte SymDecrypt(request *SymRequest) (originalData []byte, err error) //RSA //设置私钥 SetRSAPrivateKey(privateFile interface{}, pkcsLevel PKCSLevel) error //设置公钥 SetRSAPublicKey(publicData interface{}, level PKCSLevel) error //生成密钥对 GenerateRSAKey(bits int, saveDir string, pkcsLevel PKCSLevel) (privateFile, publicFile string, err error) //加密,返回[]byte RSAEncryptToBytes(data interface{}, hashType crypto.Hash, rsaType RSAEncryptType, label []byte) (cipherBytes []byte, err error) //加密,返回base64 string RSAEncryptToString(data interface{}, hashType crypto.Hash, rsaType RSAEncryptType, label []byte) (cipherString string, err error) //解密 RSADecrypt(cipherBytes interface{}, hashType crypto.Hash, rsaType RSAEncryptType, label []byte) (data []byte, err error) //签名, 返回[]byte RSASignToBytes(data interface{}, signType RSASignType, hashType crypto.Hash) (signBytes []byte, err error) //签名, 返回string RSASignToString(data interface{}, signType RSASignType, hashType crypto.Hash) (signString string, err error) //验证签名结果 RSAVerify(signBytes interface{}, data interface{}, signType RSASignType, hashType crypto.Hash) (ok bool, err error) }
对称加密器(包括DES/3DES/AES/RC4)
type EccCurveType ¶ added in v0.0.8
type EccCurveType uint
const ( ECCCurveTypeP224 EccCurveType = iota + 1 ECCCurveTypeP256 ECCCurveTypeP384 ECCCurveTypeP521 )
type Hasher ¶
type Hasher interface { HashToString(data interface{}, hashType crypto.Hash) (hashString string, err error) HashToBytes(data interface{}, hashType crypto.Hash) (hashBytes []byte, err error) DoubleHashToString(data interface{}, hashType crypto.Hash) (hashString string, err error) DoubleHashToBytes(data interface{}, hashType crypto.Hash) (hashBytes []byte, err error) MAC(hashType crypto.Hash, message, key []byte) (mac []byte) MacToString(hashType crypto.Hash, message, key []byte) (mac string) CheckMac(hashType crypto.Hash, message, key, mac []byte) bool }
hash
type RSAEncryptType ¶ added in v0.0.8
type RSAEncryptType uint //RSA加密算法类型, 用于加密、解密
const ( RSAEncryptTypeOAEP RSAEncryptType = iota + 1 //使用RSA-OAEP算法加密, 推荐使用 RSAEncryptTypePKCS1v15 //使用PKCS#1 v1.5规定的填充方案和RSA算法加密,加密的数据量有限 )
type RSASignType ¶ added in v0.0.8
type RSASignType uint //RSA签名类型
const ( RSASignTypePKCS1v15 RSASignType = iota + 1 RSASignTypePSS )
type Signer ¶
type Signer interface { //ECC椭圆曲线签名 SetECCKey(privateFile string) error GenerateECCKey(curveType EccCurveType, saveDir string) (privateFile, publicFile string, err error) EccSignToBytes(data interface{}, hashType crypto.Hash) ([]byte, error) EccSignToString(data interface{}, hashType crypto.Hash) (string, error) EccVerify(signData interface{}, originalData interface{}, hashType crypto.Hash) (ok bool, err error) //DSA签名 GenerateDSAKey(size dsa.ParameterSizes) (err error) GetDSAPrivateKey() *dsa.PrivateKey DSASignToBytes(data interface{}, hashType crypto.Hash) ([]byte, error) DSASignToString(data interface{}, hashType crypto.Hash) (string, error) DSAVerify(data interface{}, signed interface{}, hashType crypto.Hash) (bool, error) //Ed25519签名 GetEd25519Key() (ed25519.PublicKey, ed25519.PrivateKey) Ed25519SignToBytes(data interface{}) ([]byte, error) Ed25519SignToString(data interface{}) (string, error) Ed25519Verify(data interface{}, signed interface{}) (bool, error) }
数字签名
type SymRequest ¶
type SymRequest struct { PlainData interface{} //明文,用于加密 CipherData interface{} //密文,用于解密,两种类型:[]byte或者string Key []byte //密钥 Type SymType //加密类型 ModeType BlockMode //分组方式 PaddingType paddingType //填充方式 Iv []byte //iv AddData []byte //GCM模式下额外的验证数据, 如果使用GCM模式, 需要将nonce传递给解密方 Nonce []byte // GCM模式下的加密、解密随机向量 }
SymRequest 对称加密消息请求
Click to show internal directories.
Click to hide internal directories.