crypto

package
v0.0.0-...-8079b06 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2018 License: LGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KEY_LENGTH      = 8
	KEY_LENGTH_24   = KEY_LENGTH * 3
	KEY_LENGTH_128  = KEY_LENGTH * 16
	KEY_LENGTH_192  = KEY_LENGTH * 24
	KEY_LENGTH_256  = KEY_LENGTH * 32
	KEY_LENGTH_1024 = KEY_LENGTH * 128
	KEY_LENGTH_2048 = KEY_LENGTH * 256
)
View Source
const (
	LENGTH_IV           = 32
	LENGTH_TJ           = 64
	LENGTH_BYTES_OF_INT = 4
	LENGTH_DIGEST       = 32
	LENGTH_BLOCK        = 64
	TJ_START            = 0xA748B290
	DEFAULT_IV          = "a12BC!@&def568%$Gh9#ijKlmNoPqr43"
	DEFAULT_GAP         = 256
)

Variables

View Source
var (
	MD5       = md5.New()
	SHA1      = sha1.New()
	SHA256    = sha256.New()
	SHA512    = sha512.New()
	CHINA_SM3 = NewSM3()
)

Functions

func Digest

func Digest(hash hash.Hash, src []byte) []byte

message digest, with given hash algorithm. hash should be MD5,SHA1,SHA256,SHA512,CHINA_SM3, which is defined in current file src is the bytes to be digested

func DigestString

func DigestString(hash hash.Hash, src string, base64Encoding bool) string

message digest, with given hash algorithm. hash should be MD5,SHA1,SHA256,SHA512,CHINA_SM3, which is defined in current file src is the string to be digested if base64Encoding is true, result string will be encoded with base64, else will be encoded with hex

func DigestX

func DigestX(hash hash.Hash, src []byte) []byte

message digest, with given hash algorith. after digested, src will be added to result. hash should be MD5,SHA1,SHA256,SHA512,CHINA_SM3, which is defined in current file src is the bytes to be digested

func DigestXString

func DigestXString(hash hash.Hash, src string, base64Encoding bool) string

message digest, with given hash algorithm. after digested, src will be added to result. hash should be MD5,SHA1,SHA256,SHA512,CHINA_SM3, which is defined in current file src is the string to be digested if base64Encoding is true, result string will be encoded with base64, else will be encoded with hex

func SM3Digest

func SM3Digest(src []byte) []byte

func SM3Digest2

func SM3Digest2(src []byte, iv string, gap int16) []byte

func SM3DigestString

func SM3DigestString(src string, base64Encoding bool) string

func SM3DigestString2

func SM3DigestString2(src string, base64Encoding bool, iv string, gap int16) string

Types

type AES

type AES struct {
	// contains filtered or unexported fields
}

func NewAESInstance

func NewAESInstance(key string) (*AES, error)

create aes instance, use given key string. in this method, key length is set to 128bit, and iv equals to key

func NewAESInstance2

func NewAESInstance2(key string, keyLength int) (*AES, error)

create aes instance with given key string & key length. key length should be 128, 256, 512 etc. in this method, iv equals to key

func NewAESInstance3

func NewAESInstance3(key, iv string) (*AES, error)

create aes instance with given key & iv string. in this method, key length is set to 128bit

func NewAESInstance4

func NewAESInstance4(key, iv string, keyLength int) (*AES, error)

create aes instance with given key & iv string & key length.

func NewAESInstance5

func NewAESInstance5(key []byte, keyLength int) (*AES, error)

create aes instance with given key bytes & key length. in this method, iv equals to key

func NewAESInstance6

func NewAESInstance6(key, iv []byte, keyLength int) (*AES, error)

create aes instance with given key/iv bytes & key length.

func (*AES) Decrypt

func (a *AES) Decrypt(encrypted []byte) []byte

decrypt encrypted bytes. encrypted should be encrypted in CBC mode

func (*AES) DecryptString

func (a *AES) DecryptString(encrypted string, base64Encoding bool) (string, error)

decrypt encrypted string. encrypted should be encrypted in CBC mode if base64Encoding is true, means the encrypted string is encoded with base64, else is encoded with hex

func (*AES) Encrypt

func (a *AES) Encrypt(src []byte) []byte

encrypt src bytes. just support CBC mode

func (*AES) EncryptString

func (a *AES) EncryptString(src string, base64Encoding bool) string

encrypt src string. just supprt CBC mode if base64Encoding is true, result will be encoded with base64, else with hex

type DES

type DES struct {
	// contains filtered or unexported fields
}

func NewDESInstance

func NewDESInstance(key string) (*DES, error)

func NewDESInstance2

func NewDESInstance2(key, iv string) (*DES, error)

func NewDESInstance3

func NewDESInstance3(key []byte) (*DES, error)

func NewDESInstance4

func NewDESInstance4(key, iv []byte) (*DES, error)

func NewTriDESInstance

func NewTriDESInstance(key string) (*DES, error)

func NewTriDESInstance2

func NewTriDESInstance2(key, iv string) (*DES, error)

func NewTriDESInstance3

func NewTriDESInstance3(key []byte) (*DES, error)

func NewTriDESInstance4

func NewTriDESInstance4(key, iv []byte) (*DES, error)

func (*DES) DESDecrypt

func (d *DES) DESDecrypt(encrypted []byte) []byte

func (*DES) DESDecryptString

func (d *DES) DESDecryptString(encrypted string, base64Encoding bool) (string, error)

func (*DES) DESEncrypt

func (d *DES) DESEncrypt(src []byte) []byte

func (*DES) DESEncryptString

func (d *DES) DESEncryptString(src string, base64Encoding bool) string

func (*DES) TriDESDecrypt

func (d *DES) TriDESDecrypt(encrypted []byte) []byte

func (*DES) TriDESDecryptString

func (d *DES) TriDESDecryptString(encrypted string, base64Encoding bool) (string, error)

func (*DES) TriDESEncrypt

func (d *DES) TriDESEncrypt(src []byte) []byte

func (*DES) TriDESEncryptString

func (d *DES) TriDESEncryptString(src string, base64Encoding bool) string

type DSA

type DSA struct {
	// contains filtered or unexported fields
}

func NewDSAInstance

func NewDSAInstance() *DSA

func (*DSA) GenKeyPair

func (d *DSA) GenKeyPair(paramSize dsa.ParameterSizes) error

func (*DSA) Sign

func (d *DSA) Sign(src []byte) (r, s *big.Int, err error)

func (*DSA) Sign2

func (d *DSA) Sign2(src []byte, hash crypto.Hash) (r, s *big.Int, err error)

func (*DSA) SignString

func (d *DSA) SignString(src string, base64Encoding bool) (r, s string, err error)

func (*DSA) Verify

func (d *DSA) Verify(src []byte, r, s *big.Int) bool

func (*DSA) Verify2

func (d *DSA) Verify2(src []byte, hash crypto.Hash, r, s *big.Int) bool

func (*DSA) VerifyString

func (d *DSA) VerifyString(src, r, s string, base64Encoding bool) (bool, error)

type ECDSA

type ECDSA struct {
	// contains filtered or unexported fields
}

func NewECDSAInstance

func NewECDSAInstance() *ECDSA

func (*ECDSA) GenKeyPair

func (e *ECDSA) GenKeyPair(c elliptic.Curve) error

func (*ECDSA) LoadKeyPair

func (e *ECDSA) LoadKeyPair(pubKeyFile, priKeyFile string) error

func (*ECDSA) LoadPrivateKey

func (e *ECDSA) LoadPrivateKey(priKeyFile string) error

func (*ECDSA) LoadPublicKey

func (e *ECDSA) LoadPublicKey(pubKeyFile string) error

func (*ECDSA) SaveKeyPair

func (e *ECDSA) SaveKeyPair(pubKeyFile, priKeyFile string) error

func (*ECDSA) SavePrivateKey

func (e *ECDSA) SavePrivateKey(priKeyFile string) error

func (*ECDSA) SavePublicKey

func (e *ECDSA) SavePublicKey(pubKeyFile string) error

func (*ECDSA) Sign

func (e *ECDSA) Sign(src []byte) (r, s *big.Int, err error)

func (*ECDSA) Sign2

func (e *ECDSA) Sign2(src []byte, hash crypto.Hash) (r, s *big.Int, err error)

func (*ECDSA) SignString

func (e *ECDSA) SignString(src string, base64Encoding bool) (r, s string, err error)

func (*ECDSA) Verify

func (e *ECDSA) Verify(src []byte, r, s *big.Int) bool

func (*ECDSA) Verify2

func (e *ECDSA) Verify2(src []byte, hash crypto.Hash, r, s *big.Int) bool

func (*ECDSA) VerifyString

func (e *ECDSA) VerifyString(src, r, s string, base64Encoding bool) (bool, error)

type RC4

type RC4 struct {
	// contains filtered or unexported fields
}

func NewRC4Instance

func NewRC4Instance(key string) (*RC4, error)

func NewRC4Instance2

func NewRC4Instance2(key string, keyLength int) (*RC4, error)

func NewRC4Instance3

func NewRC4Instance3(key, iv string) (*RC4, error)

func NewRC4Instance4

func NewRC4Instance4(key, iv string, keyLength int) (*RC4, error)

func NewRC4Instance5

func NewRC4Instance5(key []byte, keyLength int) (*RC4, error)

func NewRC4Instance6

func NewRC4Instance6(key, iv []byte, keyLength int) (*RC4, error)

func (*RC4) Decrypt

func (a *RC4) Decrypt(encrypted []byte) []byte

func (*RC4) DecryptString

func (a *RC4) DecryptString(encrypted string, base64Encoding bool) (string, error)

func (*RC4) Encrypt

func (a *RC4) Encrypt(src []byte) []byte

func (*RC4) EncryptString

func (a *RC4) EncryptString(src string, base64Encoding bool) string

type RSA

type RSA struct {
	// contains filtered or unexported fields
}

func NewRSAInstance

func NewRSAInstance() *RSA

func (*RSA) Decrypt

func (r *RSA) Decrypt(encrypted []byte) ([]byte, error)

func (*RSA) DecryptString

func (r *RSA) DecryptString(encrypted string, base64Encoding bool) (string, error)

func (*RSA) Encrypt

func (r *RSA) Encrypt(src []byte) ([]byte, error)

func (*RSA) EncryptString

func (r *RSA) EncryptString(src string, base64Encoding bool) (string, error)

func (*RSA) GenKeyPair

func (r *RSA) GenKeyPair(keyLength int) error

func (*RSA) LoadKeyPair

func (r *RSA) LoadKeyPair(pubKeyFile, priKeyFile string) error

func (*RSA) LoadPrivateKey

func (r *RSA) LoadPrivateKey(priKeyFile string) error

func (*RSA) LoadPublicKey

func (r *RSA) LoadPublicKey(pubKeyFile string) error

func (*RSA) SaveKeyPair

func (r *RSA) SaveKeyPair(pubKeyFile, priKeyFile string) error

func (*RSA) SavePrivateKey

func (r *RSA) SavePrivateKey(priKeyFile string) error

func (*RSA) SavePublicKey

func (r *RSA) SavePublicKey(pubKeyFile string) error

func (*RSA) Sign

func (r *RSA) Sign(src []byte) ([]byte, error)

func (*RSA) Sign2

func (r *RSA) Sign2(src []byte, hash crypto.Hash) ([]byte, error)

func (*RSA) SignString

func (r *RSA) SignString(src string, base64Encoding bool) (string, error)

func (*RSA) Verify

func (r *RSA) Verify(src, sign []byte) error

func (*RSA) Verify2

func (r *RSA) Verify2(src, sign []byte, hash crypto.Hash) error

func (*RSA) VerifyString

func (r *RSA) VerifyString(src, sign string, base64Encoding bool) error

type SM3

type SM3 struct {
	// contains filtered or unexported fields
}

func Clone

func Clone(sm3 SM3) *SM3

func New2SM3

func New2SM3(iv string, gap int16) *SM3

func NewSM3

func NewSM3() *SM3

func (*SM3) BlockSize

func (sm3 *SM3) BlockSize() int

func (*SM3) Reset

func (sm3 *SM3) Reset()

func (*SM3) Size

func (sm3 *SM3) Size() int

func (*SM3) Sum

func (sm3 *SM3) Sum(b []byte) []byte

func (*SM3) Write

func (sm3 *SM3) Write(b []byte) (nn int, err error)

Jump to

Keyboard shortcuts

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