Documentation
¶
Overview ¶
Package cryptox Created by xuzhuoxi on 2019-02-03. @author xuzhuoxi
Package cryptox Created by xuzhuoxi on 2019-02-03. @author xuzhuoxi
Package cryptox Created by xuzhuoxi on 2019-02-03. @author xuzhuoxi
Package cryptox Created by xuzhuoxi on 2019-02-05. @author xuzhuoxi
Package cryptox Created by xuzhuoxi on 2019-02-03. @author xuzhuoxi
Package cryptox Created by xuzhuoxi on 2019-02-04. @author xuzhuoxi
Index ¶
- func Ansix923Padding(ciphertext []byte, blockSize int) []byte
- func Ansix923UnPadding(origData []byte) []byte
- func EncodeRSAKey(privateKey *rsa.PrivateKey, publicKey *rsa.PublicKey) (private []byte, public []byte, err error)
- func EncodeRSAPrivateKeyPKCS1(private *rsa.PrivateKey) ([]byte, error)
- func EncodeRSAPrivateKeyPKCS8(private *rsa.PrivateKey) ([]byte, error)
- func EncodeRSAPublicKey(public *rsa.PublicKey) ([]byte, error)
- func EncodeSSHPublicKey(public *rsa.PublicKey) ([]byte, error)
- func GenRSAKey(bits int) (*rsa.PrivateKey, *rsa.PublicKey, error)
- func GenRSAKeyBlock(bits int) (private *pem.Block, public *pem.Block, err error)
- func GenRSAKeyFile(bits int, privateFilePath, publicFilePath string) error
- func GenSSHKeyFile(bits int, privateFilePath, publicFilePath string) error
- func Hash(hash crypto.Hash, data []byte) []byte
- func Hash2Hex(hash crypto.Hash, data []byte) string
- func HashFile(hash crypto.Hash, filePath string) []byte
- func HashFile2Hex(hash crypto.Hash, filePath string) string
- func HashString(hash crypto.Hash, data string) []byte
- func HashString2Hex(hash crypto.Hash, data string) string
- func Iso10126Padding(ciphertext []byte, blockSize int) []byte
- func Iso10126UnPadding(origData []byte) []byte
- func Md5(data []byte) string
- func Md5File(filePath string) string
- func Md5String(data string) string
- func NewECBDecrypter(b cipher.Block, iv []byte) cipher.BlockMode
- func NewECBEncrypter(b cipher.Block, iv []byte) cipher.BlockMode
- func PKCS7Padding(cipherText []byte, blockSize int) []byte
- func PKCS7UnPadding(origData []byte) []byte
- func ParseRSAPrivateKeyPKCS1(pemPrivateKey []byte) (*rsa.PrivateKey, error)
- func ParseRSAPrivateKeyPKCS8(pemPrivateKey []byte) (*rsa.PrivateKey, error)
- func ParseRSAPublicKey(pemPublicKey []byte) (*rsa.PublicKey, error)
- func ParseSSHPublicKey(publicKey []byte) (ssh.PublicKey, error)
- func RSAPrivatePkcs1ToPkcs8(pkcs1PemFileData []byte) ([]byte, error)
- func RSAPrivatePkcs8ToPkcs1(pkcs8PemFileData []byte) ([]byte, error)
- func RegisterHash(m DESMode, ef newFunc, df newFunc)
- func Sha1(data []byte) string
- func Sha1File(filePath string) string
- func Sha1String(data string) string
- func ZeroPadding(ciphertext []byte, blockSize int) []byte
- func ZeroUnPadding(origData []byte) []byte
- type BlockNilError
- type DESMode
- type FuncPadding
- type FuncUnPadding
- type IESCipher
- type IRSACipher
- type IRSAPrivateCipher
- type IRSAPublicCipher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ansix923Padding ¶
func Ansix923UnPadding ¶
func EncodeRSAKey ¶
func EncodeRSAPrivateKeyPKCS1 ¶
func EncodeRSAPrivateKeyPKCS1(private *rsa.PrivateKey) ([]byte, error)
func EncodeRSAPrivateKeyPKCS8 ¶
func EncodeRSAPrivateKeyPKCS8(private *rsa.PrivateKey) ([]byte, error)
func GenRSAKeyBlock ¶
func GenRSAKeyFile ¶
func GenSSHKeyFile ¶
func Iso10126Padding ¶
func Iso10126UnPadding ¶
func PKCS7Padding ¶
func PKCS7UnPadding ¶
func ParseRSAPrivateKeyPKCS1 ¶
func ParseRSAPrivateKeyPKCS1(pemPrivateKey []byte) (*rsa.PrivateKey, error)
func ParseRSAPrivateKeyPKCS8 ¶
func ParseRSAPrivateKeyPKCS8(pemPrivateKey []byte) (*rsa.PrivateKey, error)
func RSAPrivatePkcs1ToPkcs8 ¶
func RSAPrivatePkcs8ToPkcs1 ¶
func RegisterHash ¶
func RegisterHash(m DESMode, ef newFunc, df newFunc)
func Sha1String ¶
func ZeroPadding ¶
func ZeroUnPadding ¶
Types ¶
type BlockNilError ¶
type BlockNilError string
func (BlockNilError) Error ¶
func (e BlockNilError) Error() string
func (BlockNilError) Temporary ¶
func (e BlockNilError) Temporary() bool
func (BlockNilError) Timeout ¶
func (e BlockNilError) Timeout() bool
type DESMode ¶
type DESMode uint
DESMode ECB(electronic code book)是最简单的方式,它将明文分组加密后的结果直接成为密文分组。 优缺点:模式操作简单;明文中的重复内容将在密文中表现出来,特别对于图像数据和明文变化较少的数据;适于短报文的加密传递。
CBC(cipher block chaining)的原理是加密算法的输入是当前的明文分组和前一密文分组的异或,第一个明文分组和一个初始向量进行异或,这样同一个明文分组重复出现时会产生不同的密文分组。 特点:同一个明文分组重复出现时产生不同的密文分组;加密函数的输入是当前的明文分组和前一个密文分组的异或;每个明文分组的加密函数的输入与明文分组之间不再有固定的关系;适合加密长消息。
func (DESMode) NewDecrypter ¶
type FuncPadding ¶
type FuncUnPadding ¶
type IESCipher ¶
type IESCipher interface { Encrypt(origData []byte) ([]byte, error) Decrypt(crypted []byte) ([]byte, error) }
IESCipher DES:Data Encrytion Standard(数据加密标准),对应算法是DEA 特点:1. 对称加密 2. 同一个SK AES:Advanced Encrytion Standard(高级加密标准),对应算法Rijndael 特点:1. 对称加密 2. 一个SK扩展成多个子SK,多轮加密
func NewAESCipher ¶
func NewAESCipher(key, iv [aes.BlockSize]byte, mode DESMode, padding FuncPadding, unPadding FuncUnPadding) IESCipher
func NewDESCipher ¶
func NewDESCipher(key, iv [des.BlockSize]byte, mode DESMode, padding FuncPadding, unPadding FuncUnPadding) IESCipher
func NewTripleDESCipher ¶
func NewTripleDESCipher(key [des.BlockSize * 3]byte, iv [des.BlockSize]byte, mode DESMode, padding FuncPadding, unPadding FuncUnPadding) IESCipher
type IRSACipher ¶
type IRSACipher interface { IRSAPublicCipher IRSAPrivateCipher }
type IRSAPrivateCipher ¶
type IRSAPrivateCipher interface { PrivateKey() *rsa.PrivateKey Decrypt(crypted []byte) ([]byte, error) // Sign // hash支持如下: // crypto.MD5 // crypto.SHA1 // crypto.SHA224 // crypto.SHA256 // crypto.SHA384 // crypto.SHA512 // crypto.MD5SHA1 // crypto.RIPEMD160 Sign(origData []byte, hash crypto.Hash) ([]byte, error) }
func LoadRsaPrivateCipher ¶
func LoadRsaPrivateCipher(path string, pkcs8 bool) (IRSAPrivateCipher, error)
func NewRsaPrivateCipher ¶
func NewRsaPrivateCipher(pemPrivate []byte, pkcs8 bool) (IRSAPrivateCipher, error)
type IRSAPublicCipher ¶
type IRSAPublicCipher interface { PublicKey() *rsa.PublicKey Encrypt(origData []byte) ([]byte, error) // VerySign // hash支持如下: // crypto.MD5 // crypto.SHA1 // crypto.SHA224 // crypto.SHA256 // crypto.SHA384 // crypto.SHA512 // crypto.MD5SHA1 // crypto.RIPEMD160 VerySign(origData, signData []byte, hash crypto.Hash) error }
func LoadRsaPublicCipher ¶
func LoadRsaPublicCipher(path string) (IRSAPublicCipher, error)
func NewRsaPublicCipher ¶
func NewRsaPublicCipher(pemPublic []byte) (IRSAPublicCipher, error)