Documentation
¶
Index ¶
- Constants
- Variables
- func AesCbcDecrypt(cipherText, key []byte, ivAes ...byte) (plainText []byte, err error)
- func AesCbcEncrypt(plainText, key []byte, ivAes ...byte) (cipherText []byte, err error)
- func AesCtrDecrypt(cipherText, key []byte, ivAes ...byte) (plainText []byte, err error)
- func AesCtrEncrypt(plainText, key []byte, ivAes ...byte) (cipherText []byte, err error)
- func DesCbcDecrypt(cipherText, key []byte, ivDes ...byte) (text []byte, err error)
- func DesCbcEncrypt(plainText, key []byte, ivDes ...byte) (cipherText []byte, err error)
- func EccDecrypt(cryptText, key []byte) (msg []byte, err error)
- func EccEncrypt(plainText, key []byte) (cryptText []byte, err error)
- func EccSign(msg []byte, Key []byte) (r []byte, s []byte, err error)
- func EccVerifySign(msg []byte, Key []byte, rText, sText []byte) (b bool, err error)
- func Encrypt(rand io.Reader, pub *PublicKey, m, s1, s2 []byte) (ct []byte, err error)
- func GenKeys(filename string) (err error)
- func GetEccKey() error
- func GetRsaKey() error
- func MD5(str string) string
- func MaxSharedKeyLength(pub *PublicKey) int
- func MyXorDecrypt(text string, key []byte) []byte
- func MyXorEncrypt(text, key []byte) string
- func RsaDecrypt(cryptText, key []byte) (plainText []byte, err error)
- func RsaEncrypt(plainText, key []byte) (cryptText []byte, err error)
- func RsaPrivateDecrypt(decryptStr string, path string) (string, error)
- func RsaPublicEncrypt(encryptStr string, path string) (string, error)
- func RsaSign(msg, Key []byte) (cryptText []byte, err error)
- func RsaVerifySign(msg []byte, sign []byte, Key []byte) bool
- func TripleDesDecrypt(cipherText, key []byte, ivDes ...byte) ([]byte, error)
- func TripleDesEncrypt(plainText, key []byte, ivDes ...byte) ([]byte, error)
- type ECIESParams
- type PrivateKey
- type PublicKey
Constants ¶
Variables ¶
var ( ErrImport = fmt.Errorf("ecies: failed to import key") ErrInvalidCurve = fmt.Errorf("ecies: invalid elliptic curve") ErrInvalidParams = fmt.Errorf("ecies: invalid ECIES parameters") ErrInvalidPublicKey = fmt.Errorf("ecies: invalid public key") ErrUnsupportedECIESParameters = fmt.Errorf("ecies: unsupported ECIES parameters") )
var ( ErrKeyDataTooLong = fmt.Errorf("ecies: can't supply requested key data") ErrInvalidMessage = fmt.Errorf("ecies: invalid message") )
var ( ECIES_AES128_SHA256 = &ECIESParams{ Hash: sha256.New, hashAlgo: crypto.SHA256, Cipher: aes.NewCipher, BlockSize: aes.BlockSize, KeyLen: 16, } ECIES_AES256_SHA256 = &ECIESParams{ Hash: sha256.New, hashAlgo: crypto.SHA256, Cipher: aes.NewCipher, BlockSize: aes.BlockSize, KeyLen: 32, } ECIES_AES256_SHA384 = &ECIESParams{ Hash: sha512.New384, hashAlgo: crypto.SHA384, Cipher: aes.NewCipher, BlockSize: aes.BlockSize, KeyLen: 32, } ECIES_AES256_SHA512 = &ECIESParams{ Hash: sha512.New, hashAlgo: crypto.SHA512, Cipher: aes.NewCipher, BlockSize: aes.BlockSize, KeyLen: 32, } )
var ErrTag = struct { ErrCipherKey error ErrKeyLengthSixteen error ErrKeyLengtheEight error ErrKeyLengthTwentyFour error ErrPaddingSize error ErrIvAes error ErrIvDes error }{ 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"), ErrKeyLengtheEight: 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"), }
ErrTag err tags
Functions ¶
func AesCbcDecrypt ¶
func AesCbcEncrypt ¶
encrypt
func AesCtrDecrypt ¶
func AesCtrEncrypt ¶
func DesCbcDecrypt ¶
func DesCbcEncrypt ¶
func EccDecrypt ¶
The private key and plaintext are passed in for decryption
func EccEncrypt ¶
The public key and plaintext are passed in for encryption
func EccVerifySign ¶
func Encrypt ¶
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 MaxSharedKeyLength ¶
MaxSharedKeyLength returns the maximum length of the shared key the public key can produce.
func RsaDecrypt ¶
func RsaEncrypt ¶
func RsaPrivateDecrypt ¶
私钥解密
func TripleDesDecrypt ¶
Types ¶
type ECIESParams ¶
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 ¶
func ParamsFromCurve(curve elliptic.Curve) (params *ECIESParams)
以下为从以太坊源码/crypt/ecies/params.go中截取过来
type PrivateKey ¶
PrivateKey is a representation of an elliptic curve private key.
func GenerateKey ¶
func GenerateKey(rand io.Reader, curve elliptic.Curve, params *ECIESParams) (prv *PrivateKey, err error)
Generate an elliptic curve public / private keypair. If params is nil, the recommended default parameters for the key will be chosen.
func ImportECDSA ¶
func ImportECDSA(prv *ecdsa.PrivateKey) *PrivateKey
Import an ECDSA private key as an ECIES private key.
func (*PrivateKey) Decrypt ¶
func (prv *PrivateKey) Decrypt(c, s1, s2 []byte) (m []byte, err error)
Decrypt decrypts an ECIES ciphertext.
func (*PrivateKey) ExportECDSA ¶
func (prv *PrivateKey) ExportECDSA() *ecdsa.PrivateKey
Export an ECIES private key as an ECDSA private key.
func (*PrivateKey) GenerateShared ¶
func (prv *PrivateKey) GenerateShared(pub *PublicKey, skLen, macLen int) (sk []byte, err error)
ECDH key agreement method used to establish secret keys for encryption.
type PublicKey ¶
PublicKey is a representation of an elliptic curve public key.
func ImportECDSAPublic ¶
Import an ECDSA public key as an ECIES public key.
func (*PublicKey) ExportECDSA ¶
Export an ECIES public key as an ECDSA public key.