cryptox

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 17 Imported by: 1

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ansix923Padding

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

func Ansix923UnPadding

func Ansix923UnPadding(origData []byte) []byte

func EncodeRSAKey

func EncodeRSAKey(privateKey *rsa.PrivateKey, publicKey *rsa.PublicKey) (private []byte, public []byte, err error)

func EncodeRSAPrivateKeyPKCS1

func EncodeRSAPrivateKeyPKCS1(private *rsa.PrivateKey) ([]byte, error)

func EncodeRSAPrivateKeyPKCS8

func EncodeRSAPrivateKeyPKCS8(private *rsa.PrivateKey) ([]byte, error)

func EncodeRSAPublicKey

func EncodeRSAPublicKey(public *rsa.PublicKey) ([]byte, error)

func EncodeSSHPublicKey

func EncodeSSHPublicKey(public *rsa.PublicKey) ([]byte, error)

func GenRSAKey

func GenRSAKey(bits int) (*rsa.PrivateKey, *rsa.PublicKey, error)

GenRSAKey bits:密钥长度

func GenRSAKeyBlock

func GenRSAKeyBlock(bits int) (private *pem.Block, public *pem.Block, err error)

func GenRSAKeyFile

func GenRSAKeyFile(bits int, privateFilePath, publicFilePath string) error

func GenSSHKeyFile

func GenSSHKeyFile(bits int, privateFilePath, publicFilePath string) error

func Hash

func Hash(hash crypto.Hash, data []byte) []byte

func Hash2Hex

func Hash2Hex(hash crypto.Hash, data []byte) string

func HashFile

func HashFile(hash crypto.Hash, filePath string) []byte

func HashFile2Hex

func HashFile2Hex(hash crypto.Hash, filePath string) string

func HashString

func HashString(hash crypto.Hash, data string) []byte

func HashString2Hex

func HashString2Hex(hash crypto.Hash, data string) string

func Iso10126Padding

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

func Iso10126UnPadding

func Iso10126UnPadding(origData []byte) []byte

func Md5

func Md5(data []byte) string

func Md5File

func Md5File(filePath string) string

func Md5String

func Md5String(data string) string

func NewECBDecrypter

func NewECBDecrypter(b cipher.Block, iv []byte) cipher.BlockMode

func NewECBEncrypter

func NewECBEncrypter(b cipher.Block, iv []byte) cipher.BlockMode

func PKCS7Padding

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

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

func ParseRSAPrivateKeyPKCS1

func ParseRSAPrivateKeyPKCS1(pemPrivateKey []byte) (*rsa.PrivateKey, error)

func ParseRSAPrivateKeyPKCS8

func ParseRSAPrivateKeyPKCS8(pemPrivateKey []byte) (*rsa.PrivateKey, error)

func ParseRSAPublicKey

func ParseRSAPublicKey(pemPublicKey []byte) (*rsa.PublicKey, error)

func ParseSSHPublicKey

func ParseSSHPublicKey(publicKey []byte) (ssh.PublicKey, error)

func RSAPrivatePkcs1ToPkcs8

func RSAPrivatePkcs1ToPkcs8(pkcs1PemFileData []byte) ([]byte, error)

func RSAPrivatePkcs8ToPkcs1

func RSAPrivatePkcs8ToPkcs1(pkcs8PemFileData []byte) ([]byte, error)

func RegisterHash

func RegisterHash(m DESMode, ef newFunc, df newFunc)

func Sha1

func Sha1(data []byte) string

func Sha1File

func Sha1File(filePath string) string

func Sha1String

func Sha1String(data string) string

func ZeroPadding

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

func ZeroUnPadding

func ZeroUnPadding(origData []byte) []byte

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)的原理是加密算法的输入是当前的明文分组和前一密文分组的异或,第一个明文分组和一个初始向量进行异或,这样同一个明文分组重复出现时会产生不同的密文分组。 特点:同一个明文分组重复出现时产生不同的密文分组;加密函数的输入是当前的明文分组和前一个密文分组的异或;每个明文分组的加密函数的输入与明文分组之间不再有固定的关系;适合加密长消息。

const (
	ECB DESMode = 1 + iota
	CBC
	CTR
	OFB
	CFB
)

func (DESMode) Available

func (m DESMode) Available() bool

func (DESMode) NewDecrypter

func (m DESMode) NewDecrypter(block cipher.Block, iv []byte) cipher.BlockMode

func (DESMode) NewEncrypter

func (m DESMode) NewEncrypter(block cipher.Block, iv []byte) cipher.BlockMode

type FuncPadding

type FuncPadding func(ciphertext []byte, blockSize int) []byte

type FuncUnPadding

type FuncUnPadding func(origData []byte) []byte

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)

Jump to

Keyboard shortcuts

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