security

package
v0.0.0-...-6d34543 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func AESDecrypt

func AESDecrypt(crypted, key []byte, mod AESMOD) ([]byte, error)

func AESDecryptIV

func AESDecryptIV(crypted, key, iv []byte, mod AESMOD) ([]byte, error)

func AESEncrypt

func AESEncrypt(origData, key []byte, mod AESMOD) ([]byte, error)

func AESEncryptIV

func AESEncryptIV(origData, key, iv []byte, mod AESMOD) ([]byte, error)

func DecodeBase64

func DecodeBase64(cipherdata []byte) []byte

func DecodeHex

func DecodeHex(hexdata []byte) []byte

func DesDecrypt

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

func DesEncrypt

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

func DoubleDesDecrypt

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

3DES 16 DEC

func DoubleDesEncrypt

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

3DES 16 ENC

func EncodeBase64

func EncodeBase64(origdata []byte) []byte

func EncodeHex

func EncodeHex(origdata []byte) []byte

func GenMACANSI99

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

func GenMd5

func GenMd5(origData []byte) string

func GenMd5HEX

func GenMd5HEX(origData []byte) string

func GetFileMd5

func GetFileMd5(filename string) (string, error)

func GetMd5

func GetMd5(origData []byte) []byte

func HMacMD5

func HMacMD5(origData, key []byte) []byte

func Hash

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

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 TripleDesDecrypt

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

3DES解密

func TripleDesEncrypt

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

3DES加密

func TripleEcbDesDecrypt

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

[golang ECB 3DES Decrypt]

func TripleEcbDesEncrypt

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

func VerifyMd5

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

Types

type AESMOD

type AESMOD int
const (
	AES_CBC_PKCS5PADDING AESMOD = iota
	AES_CBC_PKCS7PADDING
	AES_CBC_ZEROPADDING
	AES_ECB_PKCS5PADDING
	AES_ECB_PKCS7PADDING
	AES_ECB_ZEROPADDING
)

type CertInfo

type CertInfo struct {
	KeyType string
	KeyFile string
	KeyPass string
	// contains filtered or unexported fields
}

func NewCertInfo

func NewCertInfo(cfg map[string]string) (*CertInfo, error)

func NewCertInfoCer

func NewCertInfoCer(cerkey string) (*CertInfo, error)

func (*CertInfo) DecryptPKCS1v15

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

私钥解密

func (*CertInfo) EncryptPKCS1v15

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

公钥加密:

func (*CertInfo) SerialNumber

func (cert *CertInfo) SerialNumber() string

获取证书信息

func (*CertInfo) Sign

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

algo 算法:

signbuf 签名串
signature 签名值

func (*CertInfo) Verify

func (cert *CertInfo) Verify(algo int, signbuf []byte, signature []byte) error

algo 算法:

signbuf 签名串
signature 签名值

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 LoadRSAPrivatePEM

func LoadRSAPrivatePEM(buf string) (*RSAKey, error)

使用RSA私钥装载

func LoadRSAPubicPEM

func LoadRSAPubicPEM(buf string) (*RSAKey, error)

使用RSA公钥装载

func NewRSA

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

func NewRSAInMap

func NewRSAInMap(cfg map[string]string) (*RSAKey, error)

func NewRSAOfCer

func NewRSAOfCer(cfg map[string]string) (*RSAKey, error)

func (*RSAKey) DecryptPKCS1v15

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

func (*RSAKey) DecryptPKCS1v15PUB

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

func (*RSAKey) EncryptPKCS1v15

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

func (*RSAKey) EncryptPKCS1v15PRI

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

func (*RSAKey) GetModules

func (r *RSAKey) GetModules() int

func (*RSAKey) Sha1

func (r *RSAKey) Sha1(signbuf []byte) []byte

func (*RSAKey) Sign

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

func (*RSAKey) Verify

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

Directories

Path Synopsis
Package pkcs12 implements some of PKCS#12.
Package pkcs12 implements some of PKCS#12.
internal/rc2
Package rc2 implements the RC2 cipher
Package rc2 implements the RC2 cipher

Jump to

Keyboard shortcuts

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