Documentation ¶
Index ¶
- Constants
- Variables
- func AesCbcDecrypt(cipherText, secretKey, ivAes []byte) ([]byte, error)
- func AesCbcDecryptByBase64(cipherTextBase64 string, secretKey, ivAes []byte) ([]byte, error)
- func AesCbcDecryptByHex(cipherTextHex string, secretKey, ivAes []byte) ([]byte, error)
- func AesCbcEncrypt(plainText, secretKey, ivAes []byte) (cipherText []byte, err error)
- func AesCbcEncryptBase64(plainText, secretKey, ivAes []byte) (string, error)
- func AesCbcEncryptHex(plainText, secretKey, ivAes []byte) (string, error)
- func AesCtrDecrypt(cipherText, secretKey, ivAes []byte) (plainText []byte, err error)
- func AesCtrDecryptByBase64(cipherTextBase64 string, secretKey, ivAes []byte) ([]byte, error)
- func AesCtrDecryptByHex(cipherTextHex string, secretKey, ivAes []byte) ([]byte, error)
- func AesCtrEncrypt(plainText, secretKey, ivAes []byte) (cipherText []byte, err error)
- func AesCtrEncryptBase64(plainText, secretKey, ivAes []byte) (string, error)
- func AesCtrEncryptHex(plainText, secretKey, ivAes []byte) (string, error)
- func AesEcbDecrypt(plainText, secretKey []byte) ([]byte, error)
- func AesEcbDecryptByBase64(cipherTextBase64 string, key []byte) ([]byte, error)
- func AesEcbDecryptByHex(cipherTextHex string, key []byte) ([]byte, error)
- func AesEcbEncrypt(plainText, secretKey []byte) ([]byte, error)
- func AesEcbEncryptBase64(plainText, key []byte) (string, error)
- func AesEcbEncryptHex(plainText, key []byte) (string, error)
- func DesCbcDecrypt(cipherText, secretKey, ivDes []byte) (plainText []byte, err error)
- func DesCbcDecryptByBase64(cipherTextBase64 string, secretKey, ivAes []byte) (plainText []byte, err error)
- func DesCbcDecryptByHex(cipherTextHex string, secretKey, ivAes []byte) (plainText []byte, err error)
- func DesCbcEncrypt(plainText, secretKey, ivDes []byte) (cipherText []byte, err error)
- func DesCbcEncryptBase64(plainText, secretKey, ivAes []byte) (cipherTextBase64 string, err error)
- func DesCbcEncryptHex(plainText, secretKey, ivAes []byte) (cipherTextHex string, err error)
- func EccDecryptByBase64(base64CipherText, base64PriKey string) (plainText []byte, err error)
- func EccDecryptByHex(hexCipherText, hexPriKey string) (plainText []byte, err error)
- func EccEncryptToBase64(plainText []byte, base64PubKey string) (base64CipherText string, err error)
- func EccEncryptToHex(plainText []byte, hexPubKey string) (hexCipherText string, err error)
- func EccSignBase64(msg []byte, base64PriKey string) (base64rSign, base64sSign string, err error)
- func EccSignHex(msg []byte, hexPriKey string) (hexrSign, hexsSign string, err error)
- func EccVerifySignBase64(msg []byte, base64rSign, base64sSign, base64PubKey string) bool
- func EccVerifySignHex(msg []byte, hexrSign, hexsSign, hexPubKey string) bool
- func Encrypt(rand io.Reader, pub *PublicKey, m, s1, s2 []byte) (ct []byte, err error)
- func GenerateRsaKey(bits int) (*rsa.PrivateKey, error)
- func HmacSha256(key []byte, body string) []byte
- func HmacSha256Hex(key []byte, body string) string
- func HmacSha512(key []byte, body string) []byte
- func HmacSha512Hex(key []byte, body string) string
- func MD5To16Upper(value string) string
- func MD5Upper(value string) string
- func MaxSharedKeyLength(pub *PublicKey) int
- func Md5(str string) string
- func Md5SaltMulti(str string, salt string, iteration int) string
- func Md5To16(str string) string
- func Md5WithSalt(str string, salt string) string
- func Murmur128Hash(data []byte) (uint64, uint64)
- func Murmur128HashWithSeed(seed uint32, data []byte) (uint64, uint64)
- func Murmur32Hash(data []byte) uint32
- func Murmur32HashWithSeed(seed uint32, data []byte) uint32
- func Murmur64Hash(data []byte) uint64
- func Murmur64HashWithSeed(seed uint32, data []byte) uint64
- func New32() hash.Hash32
- func New32WithSeed(seed uint32) hash.Hash32
- func New64() hash.Hash64
- func New64WithSeed(seed uint32) hash.Hash64
- func PKCS5Padding(plainText []byte, blockSize int) []byte
- func PKCS5UnPadding(plainText []byte, blockSize int) ([]byte, error)
- func RsaDecryptByBase64(base64CipherText, base64PriKey string) (plainText []byte, err error)
- func RsaDecryptByHex(hexCipherText, hexPriKey string) (plainText []byte, err error)
- func RsaEncryptToBase64(plainText []byte, base64PubKey string) (base64CipherText string, err error)
- func RsaEncryptToHex(plainText []byte, hexPubKey string) (hexCipherText string, err error)
- func RsaSignBase64(msg []byte, base64PriKey string) (base64Sign string, err error)
- func RsaSignHex(msg []byte, hexPriKey string) (hexSign string, err error)
- func RsaVerifySignBase64(msg []byte, base64Sign, base64PubKey string) bool
- func RsaVerifySignHex(msg []byte, hexSign, hexPubKey string) bool
- func Sha1(data []byte) []byte
- func Sha1Hex(data []byte) string
- func Sha256(data []byte) []byte
- func Sha256Hex(data []byte) string
- func Sha512(data []byte) []byte
- func Sha512Hex(data []byte) string
- func Sum128(data []byte) (h1 uint64, h2 uint64)
- func Sum128WithSeed(data []byte, seed uint32) (h1 uint64, h2 uint64)
- func Sum32(data []byte) uint32
- func Sum32WithSeed(data []byte, seed uint32) uint32
- func Sum64(data []byte) uint64
- func Sum64WithSeed(data []byte, seed uint32) uint64
- func TripleDesDecrypt(cipherText, secretKey, ivDes []byte) ([]byte, error)
- func TripleDesDecryptByBase64(cipherTextBase64 string, secretKey, ivAes []byte) ([]byte, error)
- func TripleDesDecryptByHex(cipherTextHex string, secretKey, ivAes []byte) ([]byte, error)
- func TripleDesEncrypt(plainText, secretKey, ivDes []byte) ([]byte, error)
- func TripleDesEncryptBase64(plainText, secretKey, ivAes []byte) (string, error)
- func TripleDesEncryptHex(plainText, secretKey, ivAes []byte) (string, error)
- func ZeroPadding(ciphertext []byte, blockSize int) []byte
- func ZeroUnPadding(origData []byte) []byte
- type ECIESParams
- type EccKey
- type Hash128
- type PrivateKey
- type PublicKey
- type RsaKey
Constants ¶
const ( KeyLength8 = 8 KeyLength16 = 16 KeyLength24 = 24 KeyLength32 = 32 )
Variables ¶
var ( EciesAes128Sha256 = &ECIESParams{ Hash: sha256.New, hashAlgo: crypto.SHA256, Cipher: aes.NewCipher, BlockSize: aes.BlockSize, KeyLen: 16, } EciesAes256Sha384 = &ECIESParams{ Hash: sha512.New384, hashAlgo: crypto.SHA384, Cipher: aes.NewCipher, BlockSize: aes.BlockSize, KeyLen: 32, } EciesAes256Sha512 = &ECIESParams{ Hash: sha512.New, hashAlgo: crypto.SHA512, Cipher: aes.NewCipher, BlockSize: aes.BlockSize, KeyLen: 32, } )
var ( ErrCipherKey = errors.New("the secret key is wrong and cannot be decrypted. Please check") ErrKeyLengthSixteen = errors.New("a sixteen or twenty-four or thirty-two length secret key is required") ErrKeyLengthEight = errors.New("a eight-length secret key is required") ErrKeyLengthTwentyFour = errors.New("a twenty-four-length secret key is required") ErrPaddingSize = errors.New("padding size error please check the secret key or iv") ErrIvAes = errors.New("a sixteen-length ivaes is required") ErrIvDes = errors.New("a eight-length ivdes key is required") ErrRsaBits = errors.New("bits 1024 or 2048") ErrAesSrcBlockSize = errors.New("the length of src must be a multiple of the block size") )
var ( ErrImport = errors.New("ecies: failed to import key") ErrInvalidCurve = errors.New("ecies: invalid elliptic curve") ErrInvalidParams = errors.New("ecies: invalid ECIES parameters") ErrInvalidPublicKey = errors.New("ecies: invalid public key") ErrUnsupportedECIESParameters = errors.New("ecies: unsupported ECIES parameters") ErrKeyDataTooLong = errors.New("ecies: can't supply requested key data") ErrInvalidMessage = errors.New("ecies: invalid message") )
Functions ¶
func AesCbcDecrypt ¶ added in v1.1.3
AesCbcDecrypt @param cipherText 加密后的数据 @param secretKey 密钥 @param ivAes 和secretKey位数一致的偏移向量,默认的偏移量就是密钥
func AesCbcDecryptByBase64 ¶ added in v1.1.3
func AesCbcDecryptByHex ¶ added in v1.1.3
func AesCbcEncrypt ¶ added in v1.1.3
AesCbcEncrypt CBC 密文分组链接模式,可以避免ECB模式的缺陷 @param plainText 待加密的数据 @param secretKey 密钥 @param ivAes 和secretKey位数一致的偏移向量,默认的偏移量就是密钥
func AesCbcEncryptBase64 ¶ added in v1.1.3
func AesCbcEncryptHex ¶ added in v1.1.3
func AesCtrDecrypt ¶ added in v1.1.3
AesCtrDecrypt AES CTR模式的解密,NoPadding @param cipherText 加密后的数据 @param secretKey 密钥 @param ivAes 和secretKey位数一致的偏移向量,默认的偏移量就是密钥
func AesCtrDecryptByBase64 ¶ added in v1.1.3
func AesCtrDecryptByHex ¶ added in v1.1.3
func AesCtrEncrypt ¶ added in v1.1.3
AesCtrEncrypt AES CTR(计数器模式)模式的加密,NoPadding @param plainText 代加密的数据 @param secretKey 密钥 @param ivAes 和secretKey位数一致的偏移向量,默认的偏移量就是密钥
func AesCtrEncryptBase64 ¶ added in v1.1.3
func AesCtrEncryptHex ¶ added in v1.1.3
func AesEcbDecrypt ¶ added in v1.1.3
AesEcbDecrypt AES ECB式的解密,NoPadding @param cipherText 加密后的数据 @param secretKey 密钥
func AesEcbDecryptByBase64 ¶ added in v1.1.3
func AesEcbDecryptByHex ¶ added in v1.1.3
func AesEcbEncrypt ¶ added in v1.1.3
AesEcbEncrypt AES ECB式的加密,NoPadding @param cipherText 待加密的数据 @param secretKey 密钥
func AesEcbEncryptBase64 ¶ added in v1.1.3
func AesEcbEncryptHex ¶ added in v1.1.3
func DesCbcDecrypt ¶ added in v1.1.3
DesCbcDecrypt DES解密
func DesCbcDecryptByBase64 ¶ added in v1.1.3
func DesCbcDecryptByHex ¶ added in v1.1.3
func DesCbcEncrypt ¶ added in v1.1.3
DesCbcEncrypt DES加密
func DesCbcEncryptBase64 ¶ added in v1.1.3
func DesCbcEncryptHex ¶ added in v1.1.3
func EccDecryptByBase64 ¶ added in v1.1.3
EccDecryptByBase64 ECC使用私钥对加密后的base64字符串进行解密
func EccDecryptByHex ¶ added in v1.1.3
EccDecryptByHex ECC使用私钥对加密后的Hex字符串进行解密
func EccEncryptToBase64 ¶ added in v1.1.3
EccEncryptToBase64 ECC使用公钥进行加密后转base64
func EccEncryptToHex ¶ added in v1.1.3
EccEncryptToHex ECC使用公钥进行加密后转Hex
func EccSignBase64 ¶ added in v1.1.3
EccSignBase64 ECC签名转base64
func EccSignHex ¶ added in v1.1.3
EccSignHex ECC签名转Hex
func EccVerifySignBase64 ¶ added in v1.1.3
EccVerifySignBase64 ECC验证base64格式的签名
func EccVerifySignHex ¶ added in v1.1.3
EccVerifySignHex ECC验证hex格式的签名
func Encrypt ¶ added in v1.1.3
Encrypt encrypts a message using ECIES as specified in SEC 1, 5.1.
s1 and s2 contain shared information that is not part of the resulting ciphertext. s1 is fed into key derivation, s2 is fed into the MAC. If the shared information parameters aren't being used, they should be nil.
func GenerateRsaKey ¶ added in v1.1.3
func GenerateRsaKey(bits int) (*rsa.PrivateKey, error)
GenerateRsaKey 生成公钥和私钥
func HmacSha256 ¶ added in v1.1.3
func HmacSha256Hex ¶ added in v1.1.3
func HmacSha512 ¶ added in v1.1.3
func HmacSha512Hex ¶ added in v1.1.3
func MaxSharedKeyLength ¶ added in v1.1.3
MaxSharedKeyLength returns the maximum length of the shared key the public key can produce.
func Md5SaltMulti ¶
Md5SaltMulti 加盐并多次加密
func Murmur128Hash ¶ added in v1.1.3
func Murmur128HashWithSeed ¶ added in v1.1.3
func Murmur32Hash ¶ added in v1.1.3
func Murmur32HashWithSeed ¶ added in v1.1.3
func Murmur64Hash ¶ added in v1.1.3
func Murmur64HashWithSeed ¶ added in v1.1.3
func New32WithSeed ¶ added in v1.1.3
New32WithSeed returns new 32-bit hasher set with explicit seed value
func New64WithSeed ¶ added in v1.1.3
New64WithSeed returns a 64-bit hasher set with explicit seed value
func PKCS5Padding ¶ added in v1.1.3
func PKCS5UnPadding ¶ added in v1.1.3
func RsaDecryptByBase64 ¶ added in v1.1.3
RsaDecryptByBase64 使用私钥解密密文的base64格式
func RsaDecryptByHex ¶ added in v1.1.3
RsaDecryptByHex 使用私钥解密密文的hex格式
func RsaEncryptToBase64 ¶ added in v1.1.3
RsaEncryptToBase64 公钥加密后转base64
func RsaEncryptToHex ¶ added in v1.1.3
RsaEncryptToHex 公钥加密后转hex
func RsaSignBase64 ¶ added in v1.1.3
RsaSignBase64 私钥生成签名转base64
func RsaSignHex ¶ added in v1.1.3
RsaSignHex 私钥生成签名转hex
func RsaVerifySignBase64 ¶ added in v1.1.3
RsaVerifySignBase64 公钥验证base64格式签名
func RsaVerifySignHex ¶ added in v1.1.3
RsaVerifySignHex 公钥验证hex格式签名
func Sum128 ¶ added in v1.1.3
Sum128 returns the MurmurHash3 sum of data. It is equivalent to the following sequence (without the extra burden and the extra allocation):
hasher := New128() hasher.Write(data) return hasher.Sum128()
func Sum128WithSeed ¶ added in v1.1.3
Sum128WithSeed returns the MurmurHash3 sum of data. It is equivalent to the following sequence (without the extra burden and the extra allocation):
hasher := New128WithSeed(seed) hasher.Write(data) return hasher.Sum128()
func Sum32WithSeed ¶ added in v1.1.3
Sum32WithSeed 使用种子生成哈希值
func Sum64 ¶ added in v1.1.3
Sum64 returns the MurmurHash3 sum of data. It is equivalent to the following sequence (without the extra burden and the extra allocation):
hasher := New64() hasher.Write(data) return hasher.Sum64()
func Sum64WithSeed ¶ added in v1.1.3
Sum64WithSeed returns the MurmurHash3 sum of data. It is equivalent to the following sequence (without the extra burden and the extra allocation):
hasher := New64WithSeed(seed) hasher.Write(data) return hasher.Sum64()
func TripleDesDecrypt ¶ added in v1.1.3
func TripleDesDecryptByBase64 ¶ added in v1.1.3
func TripleDesDecryptByHex ¶ added in v1.1.3
func TripleDesEncrypt ¶ added in v1.1.3
func TripleDesEncryptBase64 ¶ added in v1.1.3
func TripleDesEncryptHex ¶ added in v1.1.3
func ZeroPadding ¶ added in v1.1.3
func ZeroUnPadding ¶ added in v1.1.3
Types ¶
type ECIESParams ¶ added in v1.1.3
type ECIESParams struct { Hash func() hash.Hash // hash function Cipher func([]byte) (cipher.Block, error) // symmetric cipher BlockSize int // block size of symmetric cipher KeyLen int // length of symmetric key // contains filtered or unexported fields }
func ParamsFromCurve ¶ added in v1.1.3
func ParamsFromCurve(curve elliptic.Curve) (params *ECIESParams)
ParamsFromCurve 以下为从以太坊源码/crypt/ecies/params.go中截取过来
type EccKey ¶ added in v1.1.3
func GenerateEccKeyBase64 ¶ added in v1.1.3
GenerateEccKeyBase64 生成ECC的私钥和公钥的base64形式
func GenerateEccKeyHex ¶ added in v1.1.3
GenerateEccKeyHex 生成ECC的私钥和公钥的Hex形式
type Hash128 ¶ added in v1.1.3
Hash128 represents a 128-bit hasher Hack: the standard api doesn't define any Hash128 interface.
func New128WithSeed ¶ added in v1.1.3
New128WithSeed returns a 128-bit hasher set with explicit seed value
type PrivateKey ¶ added in v1.1.3
PrivateKey is a representation of an elliptic curve private key.
func GenerateKey ¶ added in v1.1.3
func GenerateKey(rand io.Reader, curve elliptic.Curve, params *ECIESParams) (prv *PrivateKey, err error)
GenerateKey Generate an elliptic curve public / private keypair. If params is nil, the recommended default parameters for the key will be chosen.
func ImportECDSA ¶ added in v1.1.3
func ImportECDSA(prv *ecdsa.PrivateKey) *PrivateKey
ImportECDSA Import an ECDSA private key as an ECIES private key.
func (*PrivateKey) Decrypt ¶ added in v1.1.3
func (prv *PrivateKey) Decrypt(c, s1, s2 []byte) (m []byte, err error)
Decrypt decrypts an ECIES ciphertext.
func (*PrivateKey) ExportECDSA ¶ added in v1.1.3
func (prv *PrivateKey) ExportECDSA() *ecdsa.PrivateKey
ExportECDSA Export an ECIES private key as an ECDSA private key.
func (*PrivateKey) GenerateShared ¶ added in v1.1.3
func (prv *PrivateKey) GenerateShared(pub *PublicKey, skLen, macLen int) (sk []byte, err error)
GenerateShared ECDH key agreement method used to establish secret keys for encryption.
type PublicKey ¶ added in v1.1.3
PublicKey is a representation of an elliptic curve public key.
func ImportECDSAPublic ¶ added in v1.1.3
ImportECDSAPublic Import an ECDSA public key as an ECIES public key.
func (*PublicKey) ExportECDSA ¶ added in v1.1.3
ExportECDSA Export an ECIES public key as an ECDSA public key.
type RsaKey ¶ added in v1.1.3
func GenerateRsaKeyBase64 ¶ added in v1.1.3
GenerateRsaKeyBase64 生成公钥和私钥的base64格式
func GenerateRsaKeyHex ¶ added in v1.1.3
GenerateRsaKeyHex 生成公钥和私钥的hex格式