security

package
v0.0.0-...-66c0836 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2018 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//证书RSA
	FILE_CERT_CER = "CER"
	FILE_CERT_PFX = "PFX"
	//公私钥
	FILE_RSA_PEM_PUB  = "PEM-RSA-PUB"
	FILE_RSA_PEM_PRIV = "PEM-RSA-PRIV"
)
View Source
const (
	UnknownSignatureAlgorithm int = iota
	MD2WithRSA
	MD5WithRSA
	SHA1WithRSA
	SHA256WithRSA
	SHA384WithRSA
	SHA512WithRSA
	DSAWithSHA1
	DSAWithSHA256
	ECDSAWithSHA1
	ECDSAWithSHA256
	ECDSAWithSHA384
	ECDSAWithSHA512
)

Variables

View Source
var IV = []byte{0, 0, 0, 0, 0, 0, 0, 0}

Functions

func AesCBCDecrypt

func AesCBCDecrypt(crypted, key []byte, iv []byte) ([]byte, error)

func AesCBCEncrypt

func AesCBCEncrypt(origData, key []byte, iv []byte) ([]byte, error)

func AesEcbDecrypt

func AesEcbDecrypt(crypted, key []byte) ([]byte, error)

func AesEcbEncrypt

func AesEcbEncrypt(origData, key []byte) ([]byte, error)

func DecodeBase64

func DecodeBase64(cipherdata []byte) []byte

func DecodeHex

func DecodeHex(hexdata []byte) []byte

func DesDecrypt

func DesDecrypt(crypted, key []byte) ([]byte, gerror.IError)

func DesEncrypt

func DesEncrypt(origData, key []byte) ([]byte, gerror.IError)

var IV = []byte("01234567")

func DoubleCBCDesDecrypt

func DoubleCBCDesDecrypt(ciphertext, key []byte) (origData []byte, err gerror.IError)

func DoubleCBCDesDecryptBase64

func DoubleCBCDesDecryptBase64(crypted string, key []byte) ([]byte, gerror.IError)

func DoubleCBCDesEncrypt

func DoubleCBCDesEncrypt(origData, key []byte) (ciphertext []byte, err gerror.IError)

func DoubleDesDecrypt

func DoubleDesDecrypt(crypted, key []byte) ([]byte, gerror.IError)

2des解密

func DoubleDesEncrypt

func DoubleDesEncrypt(origData, key []byte) ([]byte, gerror.IError)

2des加密

func DoubleDesEncryptBase64

func DoubleDesEncryptBase64(origData, key []byte) (string, gerror.IError)

func EncodeBase64

func EncodeBase64(origdata []byte) []byte

func EncodeHex

func EncodeHex(origdata []byte) []byte

func GenMd5

func GenMd5(origData []byte) string

func GenRsaKey

func GenRsaKey(bits int) (priRes, pubRes string, err error)

func GetFileMd5

func GetFileMd5(filename string) (string, error)

func GetMd5

func GetMd5(origData []byte) []byte

func GetRsaPrivateKey

func GetRsaPrivateKey(filepath string) (pubKey *rsa.PrivateKey, err error)

获取私钥

func GetRsaPrivateKeyByString

func GetRsaPrivateKeyByString(prikey string) (pubKey *rsa.PrivateKey, err error)

func GetRsaPrivatePKCS8Key

func GetRsaPrivatePKCS8Key(filepath string) (pubKey *rsa.PrivateKey, err error)

func GetRsaPublicKey

func GetRsaPublicKey(filePath string) (pubKey *rsa.PublicKey, err error)

获取公钥

func GetRsaPublicKeyByString

func GetRsaPublicKeyByString(pubkey string) (pubKey *rsa.PublicKey, err error)

func Hash

func Hash(algo int, hashbuf []byte) ([]byte, error)

func HmacMd5

func HmacMd5(src, key string) string

func NewECBDecrypter

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

NewECBDecrypter returns a BlockMode which decrypts in electronic code book mode, using the given cipher.Block.

func NewECBEncrypter

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

NewECBEncrypter returns a BlockMode which encrypts in electronic code book mode, using the given cipher.Block.

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

func PKCS7UnPadding

func PKCS7UnPadding(plantText []byte) []byte

func RsaDecryptBase64

func RsaDecryptBase64(decKey *rsa.PrivateKey, ciphertext string) (origData []byte, err error)

解密

func RsaEncryptBase64

func RsaEncryptBase64(encKey *rsa.PublicKey, origData []byte) (ciphertext string, err error)

RSA 报文加密

func RsaPrivKeyModules

func RsaPrivKeyModules(priv *rsa.PrivateKey) int

func RsaPubKeyModules

func RsaPubKeyModules(pub *rsa.PublicKey) int

func RsaSignBase64

func RsaSignBase64(privSign *rsa.PrivateKey, req map[string]string) (ciphertext string, err error)

func RsaSignSha1

func RsaSignSha1(privSign *rsa.PrivateKey, data []byte) (ciphertext []byte, err error)

func RsaSignSha1Base64

func RsaSignSha1Base64(privSign *rsa.PrivateKey, data []byte) (string, error)

func RsaSignSha256

func RsaSignSha256(privSign *rsa.PrivateKey, data []byte) (ciphertext []byte, err error)

func RsaVerifyBase64

func RsaVerifyBase64(cert *x509.Certificate, respMap map[string]string) (ok bool, err error)

func RsaVerifySha1

func RsaVerifySha1(pubVerify *rsa.PublicKey, data []byte, signResu []byte) (ok bool, err error)

func RsaVerifySha1Base64

func RsaVerifySha1Base64(pubVerify *rsa.PublicKey, data string, signResu string) (ok bool, err error)

func RsaVerifySha256Base64

func RsaVerifySha256Base64(pubVerify *rsa.PublicKey, data string, signResu string) (ok bool, err error)

func TripleDesDecrypt

func TripleDesDecrypt(crypted, key []byte) ([]byte, gerror.IError)

3DES解密

func TripleDesEncrypt

func TripleDesEncrypt(origData, key []byte) ([]byte, gerror.IError)

3DES加密

func UnZlib

func UnZlib(src []byte) ([]byte, error)

func UnZlibBase64

func UnZlibBase64(src string) ([]byte, error)

func UnionRsaSignBase64Url

func UnionRsaSignBase64Url(privSign *rsa.PrivateKey, keysv map[string]string) (string, gerror.IError)

func UnionRsaVerify

func UnionRsaVerify(pubVerify *rsa.PublicKey, respMap map[string]string) (bool, gerror.IError)

func VerifyHmacMd5

func VerifyHmacMd5(src, hmaced, key []byte) bool

func VerifyMd5

func VerifyMd5(origData []byte, desKey string) bool

func ZeroPadding

func ZeroPadding(ciphertext []byte, blockSize int) []byte

func ZeroUnPadding

func ZeroUnPadding(origData []byte) []byte

func Zlib

func Zlib(src []byte) []byte

func ZlibBase64

func ZlibBase64(src []byte) string

Types

type CliCert

type CliCert struct {
	KeyType            string `json:"key_type"`
	KeyFile            string `json:"key_file"`
	SerialNumber       string `json:"serial_number"`
	X509Cert           *x509.Certificate
	PublicKey          interface{}
	PublicKeyAlgorithm x509.PublicKeyAlgorithm
}

func NewCliCert

func NewCliCert(jsonConfig string) (*CliCert, error)

func (*CliCert) EncryptPKCS1v15

func (cert *CliCert) EncryptPKCS1v15(origdata []byte) ([]byte, error)

签名公钥加密:

func (*CliCert) GetSerialNumber

func (cert *CliCert) GetSerialNumber() string

获取证书信息

func (*CliCert) Verfy

func (cert *CliCert) Verfy(algo int, signbuf, signature []byte) error

algo 算法:

signbuf 签名串
signature 签名值

type RSAKey

type RSAKey struct {
	KeyType    string `json:"key_type"`
	KeyFile    string `json:"key_file"`
	PublicKey  *rsa.PublicKey
	PrivateKey *rsa.PrivateKey
	Modules    int
}

func LoadFromRSAPrivate

func LoadFromRSAPrivate(priv *rsa.PrivateKey) (*RSAKey, error)

使用RSA私钥装载

func LoadFromRSAPublic

func LoadFromRSAPublic(pub *rsa.PublicKey) (*RSAKey, error)

使用RSA公钥装载

func NewRSA

func NewRSA(jsonConfig string) (*RSAKey, error)

func (*RSAKey) DecryptPKCS1v15

func (r *RSAKey) DecryptPKCS1v15(cipherdata []byte) ([]byte, error)

func (*RSAKey) EncryptPKCS1v15

func (r *RSAKey) EncryptPKCS1v15(origdata []byte) ([]byte, error)

func (*RSAKey) GetModules

func (r *RSAKey) GetModules() int

func (*RSAKey) Sign

func (r *RSAKey) Sign(algo int, signbuf []byte) ([]byte, error)

func (*RSAKey) Verfy

func (r *RSAKey) Verfy(algo int, signbuf []byte, signature []byte) error

type SvrCert

type SvrCert struct {
	KeyType      string `json:"key_type"`
	KeyFile      string `json:"key_file"`
	CertFile     string `json:"cert_file"`
	SerialNumber string `json:"serial_number"`
	X509Cert     *x509.Certificate
	PrivateKey   interface{}
	PublicKey    interface{}
}

func NewSvrCert

func NewSvrCert(jsonConfig string) (*SvrCert, error)

func (*SvrCert) DecryptPKCS1v15

func (cert *SvrCert) DecryptPKCS1v15(cipherdata []byte) ([]byte, error)

私钥解密

func (*SvrCert) EncryptPKCS1v15

func (cert *SvrCert) EncryptPKCS1v15(origdata []byte) ([]byte, error)

公钥加密:

func (*SvrCert) GetSerialNumber

func (cert *SvrCert) GetSerialNumber() string

获取证书信息

func (*SvrCert) Sign

func (cert *SvrCert) Sign(algo int, signbuf []byte) ([]byte, error)

algo 算法:

signbuf 签名串
signature 签名值

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL