Documentation ¶
Index ¶
- Constants
- func SHA(length int, content interface{}, decodeType int) (result string, err error)
- type Cipher
- func (c *Cipher) Decode(cipherText string) ([]byte, error)
- func (c *Cipher) Decrypt(block cipher.Block, cipherData []byte) (err error)
- func (c *Cipher) Encode() string
- func (c *Cipher) Encrypt(block cipher.Block, plainData []byte) (err error)
- func (c *Cipher) Fill(plainText []byte, blockSize int) []byte
- func (c *Cipher) NewECBDecrypter(block cipher.Block, cipherData []byte)
- func (c *Cipher) NewECBEncrypter(block cipher.Block, plainData []byte)
- func (c *Cipher) UnFill(plainText []byte) (data []byte, err error)
- type CipherAES
- type CipherDES
- func (c *CipherDES) DESDecrypt(cipherText string) (plainText string, err error)
- func (c *CipherDES) DESEncrypt(plainText []byte) (cipherText string, err error)
- func (c *CipherDES) TripleDESDecrypt(cipherText string) (plainText string, err error)
- func (c *CipherDES) TripleDESEncrypt(plainText []byte) (cipherText string, err error)
- type CipherRSA
- type CipherText
- type Crypto
- type FillMode
- type MessageDigest
Examples ¶
Constants ¶
const ( CBCMode = iota CFBMode CTRMode ECBMode OFBMode )
const ( PrintHex = iota PrintBase64 )
const ( SHA1 = iota SHA256 SHA512 )
const BlockSize = 16
Variables ¶
This section is empty.
Functions ¶
func SHA ¶ added in v1.0.2
SHA implements several hash functions, including sha1, sha256, and sha512. Meanwhile, SHA supports file hash. When content type is string, it indicates the address of the file. decodeType represents the print format, and the result is not encrypted by default.
Example ¶
result, err := SHA(SHA1, []byte("hello world"), PrintHex) if err != nil { fmt.Println(err) return } fmt.Println(result)
Output:
Types ¶
type Cipher ¶ added in v1.0.1
type Cipher struct { GroupMode int FillMode FillMode DecodeType int Key []byte Iv []byte Output CipherText }
func (*Cipher) NewECBDecrypter ¶ added in v1.0.1
func (*Cipher) NewECBEncrypter ¶ added in v1.0.1
type CipherAES ¶ added in v1.0.1
type CipherAES struct {
Cipher
}
func NewAESCipher ¶ added in v1.0.1
func (*CipherAES) AESDecrypt ¶ added in v1.0.1
type CipherDES ¶ added in v1.0.1
type CipherDES struct {
Cipher
}
func NewDESCipher ¶ added in v1.0.1
func (*CipherDES) DESDecrypt ¶ added in v1.0.1
func (*CipherDES) DESEncrypt ¶ added in v1.0.1
func (*CipherDES) TripleDESDecrypt ¶ added in v1.0.1
type CipherRSA ¶ added in v1.0.1
func NewRSACipher ¶ added in v1.0.1
New returns a CipherRSA pointer, the keyFile parameters is address of public key or private key. If the length of keyFile is 1, which means RSA encryption. If the length of keyFile greater than 1, which means RSA decryption. Meanwhile, the second element of keyFile represents private key.
func (*CipherRSA) RSADecrypt ¶ added in v1.0.1
Decrypt parses the given message with RSA private key in PKCS#1, ASN.1 DER form.
type CipherText ¶ added in v1.0.1
type CipherText []byte
type MessageDigest ¶ added in v1.0.1
type MessageDigest string
func MD5 ¶
func MD5(src interface{}) (md MessageDigest, err error)
MD5 information summary, the src has two types: []byte or string The default return value is 32-bit lowercase.
func (MessageDigest) LowerCase16 ¶ added in v1.0.1
func (md MessageDigest) LowerCase16() string
func (MessageDigest) UpperCase16 ¶ added in v1.0.1
func (md MessageDigest) UpperCase16() string
func (MessageDigest) UpperCase32 ¶ added in v1.0.1
func (md MessageDigest) UpperCase32() string