Documentation ¶
Index ¶
- Constants
- Variables
- func AESDecrypt(encrypted string, key []byte) ([]byte, error)
- func AESEncrypt(origin []byte, key []byte) (string, error)
- func ECDSASign(data []byte, method string, privateKey *ecdsa.PrivateKey) (string, error)
- func ECDSAVerify(content []byte, signature string, method string, publicKey *ecdsa.PublicKey) error
- func HMACSHA256(data, key []byte) string
- func HMACSHA512(data, key []byte) string
- func PKCS7Padding(text []byte, size int) []byte
- func PKCS7UnPadding(origData []byte) []byte
- func ParseECDSAPrivate(data []byte) (*ecdsa.PrivateKey, error)
- func ParseECDSAPublic(data []byte) (*ecdsa.PublicKey, error)
- func ParseRSAPrivateKey(key []byte) (*rsa.PrivateKey, error)
- func ParseRSAPublicKey(data []byte) (*rsa.PublicKey, error)
- func RSADecrypt(encrypted string, privateKey *rsa.PrivateKey) ([]byte, error)
- func RSAEncrypt(origData []byte, publicKey *rsa.PublicKey) (string, error)
- func RSASign(data []byte, method string, privateKey *rsa.PrivateKey) (string, error)
- func RSAVerify(content []byte, signature string, method string, publicKey *rsa.PublicKey) error
- type ECDSAKey
- type RSAKey
Constants ¶
View Source
const ( ErrBase64DecodeError = "签名base64解码异常" ErrSignatureCheckError = "签名校验失败" ErrSignatureCreateError = "签名创建失败" ErrSigningMethodError = "错误的签名方法" )
View Source
const ( SigningMethodRSA256 = "SHA256" SigningMethodRSA512 = "SHA512" SigningMethodRSA384 = "SHA384" )
Variables ¶
View Source
var ( ErrKeyMustBePEMEncoded = errors.New("invalid key: Key must be PEM encoded") ErrNotRSAPrivateKey = errors.New("key is not a valid RSA private key") ErrNotRSAPublicKey = errors.New("key is not a valid RSA public key") )
View Source
var ( // ErrNotECDSAPrivateKey = errors.New("key is not a valid ECDSA private key") ErrNotECDSAPublicKey = errors.New("key is not a valid ECDSA public key") )
Functions ¶
func AESEncrypt ¶
AESEncrypt AES CBC加密 key 长度必须为 16, 24 或 32
func ECDSAVerify ¶
ECDSAVerify ecdsa 验证签名
func ParseECDSAPrivate ¶
func ParseECDSAPrivate(data []byte) (*ecdsa.PrivateKey, error)
func ParseRSAPrivateKey ¶
func ParseRSAPrivateKey(key []byte) (*rsa.PrivateKey, error)
Types ¶
type ECDSAKey ¶
type ECDSAKey struct {
// contains filtered or unexported fields
}
func CreateECDSAKey ¶
func CreateECDSAKeyByPrivateKey ¶
func CreateECDSAKeyByPrivateKey(key *ecdsa.PrivateKey) *ECDSAKey
func (*ECDSAKey) EncodePrivateToPEM ¶
func (*ECDSAKey) EncodePublicToPem ¶
func (*ECDSAKey) PrivateKey ¶
func (ek *ECDSAKey) PrivateKey() *ecdsa.PrivateKey
type RSAKey ¶
type RSAKey struct {
// contains filtered or unexported fields
}
func CreateRSAKey ¶
func CreateRSAKeyByPrivateKey ¶
func CreateRSAKeyByPrivateKey(privateKey *rsa.PrivateKey) *RSAKey
func (*RSAKey) EncodePrivateToPEM ¶
func (*RSAKey) EncodePublicToPEM ¶
func (*RSAKey) PrivateKey ¶
func (r *RSAKey) PrivateKey() *rsa.PrivateKey
Click to show internal directories.
Click to hide internal directories.