crypto

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxFileBlock = 1 * 1024 * 1024
)

Variables

This section is empty.

Functions

func NewECBDecrypt

func NewECBDecrypt(b cipher.Block) cipher.BlockMode

NewECBDecrypt returns a BlockMode which decrypts in electronic code book mode, using the given Block.

Types

type BaseStruct

type BaseStruct struct {
	Err error
	// contains filtered or unexported fields
}

func (BaseStruct) String

func (e BaseStruct) String() string

String implements the interface Stringer for encode struct. 实现 Stringer 接口

func (BaseStruct) ToBase32Bytes

func (e BaseStruct) ToBase32Bytes() []byte

ToBase32Bytes outputs as byte slice with base32 encoding. 输出经过 base32 编码的字节切片

func (BaseStruct) ToBase32String

func (e BaseStruct) ToBase32String() string

ToBase32String outputs as string with base32 encoding. 输出经过 base32 编码的字符串

func (BaseStruct) ToBase64Bytes

func (e BaseStruct) ToBase64Bytes() []byte

ToBase64Bytes outputs as byte slice with base64 encoding. 输出经过 base64 编码的字节切片

func (BaseStruct) ToBase64String

func (e BaseStruct) ToBase64String() string

ToBase64String outputs as string with base64 encoding. 输出经过 base64 编码的字符串

func (BaseStruct) ToBytes

func (e BaseStruct) ToBytes() []byte

ToBytes outputs as byte slice. 输出字节切片

func (BaseStruct) ToHexBytes

func (e BaseStruct) ToHexBytes() []byte

ToHexBytes outputs as byte with hex encoding. 输出经过 hex 编码的字节切片

func (BaseStruct) ToHexString

func (e BaseStruct) ToHexString() string

ToHexString outputs as string with hex encoding. 输出经过 hex 编码的字符串

func (BaseStruct) ToString

func (e BaseStruct) ToString() string

ToString outputs as string. 输出字符串

type Cipher

type Cipher struct {
	PublicKey  []byte // 公钥
	PrivateKey []byte // 私钥

	Err error
	// contains filtered or unexported fields
}

Cipher defines a Cipher struct. 定义 Cipher 结构体

func NewCipher

func NewCipher() *Cipher

NewCipher returns a new Cipher instance. 初始化 Cipher 结构体

func (*Cipher) PKCS5Padding

func (c *Cipher) PKCS5Padding(src []byte) []byte

PKCS5Padding padding with PKCS5 mode. 进行 PKCS5 填充

func (*Cipher) PKCS5UnPadding

func (c *Cipher) PKCS5UnPadding(src []byte) []byte

PKCS5UnPadding removes padding with PKCS5 mode. 移除 PKCS5 填充

func (*Cipher) PKCS7Padding

func (c *Cipher) PKCS7Padding(src []byte, size int) []byte

PKCS7Padding padding with PKCS7 mode. 进行 PKCS7 填充

func (*Cipher) PKCS7UnPadding

func (c *Cipher) PKCS7UnPadding(src []byte) []byte

PKCS7UnPadding removes padding with PKCS7 mode. 移除 PKCS7 填充

func (*Cipher) Padding

func (c *Cipher) Padding(src []byte, blockSize int) []byte

func (*Cipher) RSAGeneratePrivateKey

func (c *Cipher) RSAGeneratePrivateKey(bits int) *Cipher

func (*Cipher) RSAGeneratePublicKey

func (c *Cipher) RSAGeneratePublicKey(priKeyOption ...[]byte) *Cipher

func (*Cipher) SetIV

func (c *Cipher) SetIV(iv interface{}) *Cipher

SetIV sets iv. 设置偏移向量

func (*Cipher) SetKey

func (c *Cipher) SetKey(key interface{}) *Cipher

SetKey sets key. 设置密钥

func (*Cipher) SetMode

func (c *Cipher) SetMode(mode ModeType) *Cipher

SetMode sets mode. 设置分组模式

func (*Cipher) SetPadding

func (c *Cipher) SetPadding(padding PaddingType) *Cipher

SetPadding sets padding. 设置填充模式

func (*Cipher) SetPrivateKey

func (c *Cipher) SetPrivateKey(key interface{}) *Cipher

func (*Cipher) SetPublicKey

func (c *Cipher) SetPublicKey(key interface{}) *Cipher

func (*Cipher) UnPadding

func (c *Cipher) UnPadding(src []byte) []byte

func (*Cipher) ZeroPadding

func (c *Cipher) ZeroPadding(src []byte, size int) []byte

ZeroPadding padding with Zero mode. 进行零填充

func (*Cipher) ZeroUnPadding

func (c *Cipher) ZeroUnPadding(src []byte) []byte

ZeroUnPadding removes padding with Zero mode. 移除零填充

type Decrypt

type Decrypt struct {
	BaseStruct
}

func NewDecrypt

func NewDecrypt() Decrypt

func (Decrypt) ByAes

func (e Decrypt) ByAes(c *Cipher) Decrypt

ByAes decrypts by aes algorithm. 通过 aes 解密

func (Decrypt) ByDes

func (e Decrypt) ByDes(c *Cipher) Decrypt

ByDes decrypts by aes algorithm. 通过 des 解密

func (Decrypt) ByRC4

func (e Decrypt) ByRC4(c *Cipher) Decrypt

func (Decrypt) ByRSA

func (e Decrypt) ByRSA(c *Cipher) Decrypt

func (Decrypt) ByTripleDes

func (e Decrypt) ByTripleDes(c *Cipher) Decrypt

ByTripleDes decrypts by aes algorithm. 通过 des 解密

func (Decrypt) ByXor

func (e Decrypt) ByXor(key []byte) Decrypt

func (Decrypt) FromBase32Byte

func (e Decrypt) FromBase32Byte(b []byte) Decrypt

func (Decrypt) FromBase32String

func (e Decrypt) FromBase32String(s string) Decrypt

func (Decrypt) FromBase64Byte

func (e Decrypt) FromBase64Byte(b []byte) Decrypt

func (Decrypt) FromBase64String

func (e Decrypt) FromBase64String(s string) Decrypt

func (Decrypt) FromBytes

func (e Decrypt) FromBytes(b []byte) Decrypt

FromBytes hash from byte slice. 对字节切片进行编码

func (Decrypt) FromFile

func (e Decrypt) FromFile(f interface{}) Decrypt

FromFile hash from file. 对文件进行编码

func (Decrypt) FromHexByte

func (e Decrypt) FromHexByte(b []byte) Decrypt

func (Decrypt) FromHexString

func (e Decrypt) FromHexString(s string) Decrypt

func (Decrypt) FromString

func (e Decrypt) FromString(s string) Decrypt

FromString hash from string. 对字符串进行编码

type Encrypt

type Encrypt struct {
	BaseStruct
}

func NewEncrypt

func NewEncrypt() Encrypt

func (Encrypt) ByAes

func (e Encrypt) ByAes(c *Cipher) Encrypt

ByAes encrypts by aes algorithm. 通过 aes 加密

func (Encrypt) ByDes

func (e Encrypt) ByDes(c *Cipher) Encrypt

ByDes encrypts by aes algorithm. 通过 des 加密

func (Encrypt) ByRC4

func (e Encrypt) ByRC4(c *Cipher) Encrypt

func (Encrypt) ByRSA

func (e Encrypt) ByRSA(c *Cipher) Encrypt

func (Encrypt) ByTripleDes

func (e Encrypt) ByTripleDes(c *Cipher) Encrypt

ByTripleDes encrypts by aes algorithm. 通过 des 加密

func (Encrypt) ByXor

func (e Encrypt) ByXor(key []byte) Encrypt

func (Encrypt) FromBytes

func (e Encrypt) FromBytes(b []byte) Encrypt

FromBytes hash from byte slice. 对字节切片进行编码

func (Encrypt) FromFile

func (e Encrypt) FromFile(f interface{}) Encrypt

FromFile hash from file. 对文件进行编码

func (Encrypt) FromString

func (e Encrypt) FromString(s string) Encrypt

FromString hash from string. 对字符串进行编码

type ModeType

type ModeType string

ModeType mode constants 模式常量

const (
	CBC             ModeType = "CBC"
	ECB             ModeType = "ECB"
	CFB             ModeType = "CFB"
	OFB             ModeType = "OFB"
	CTR             ModeType = "CTR"
	RSA_OAEP_SHA1   ModeType = "RSA_OAEP_SHA1"
	RSA_OAEP_MD5    ModeType = "RSA_OAEP_MD5"
	RSA_OAEP_SHA256 ModeType = "RSA_OAEP_SHA256"
	RSA_OAEP_SHA384 ModeType = "RSA_OAEP_SHA384"
	RSA_OAEP_SHA512 ModeType = "RSA_OAEP_SHA512"
	RSA_PKCS1_V1_5  ModeType = "RSA_PKCS1_V1_5"
)

func (*ModeType) CBC

func (m *ModeType) CBC() ModeType

func (*ModeType) CFB

func (m *ModeType) CFB() ModeType

func (*ModeType) CTR

func (m *ModeType) CTR() ModeType

func (*ModeType) ECB

func (m *ModeType) ECB() ModeType

func (*ModeType) OFB

func (m *ModeType) OFB() ModeType

func (*ModeType) RsaOaepMD5

func (m *ModeType) RsaOaepMD5() ModeType

func (*ModeType) RsaOaepSHA1

func (m *ModeType) RsaOaepSHA1() ModeType

func (*ModeType) RsaOaepSHA256

func (m *ModeType) RsaOaepSHA256() ModeType

func (*ModeType) RsaOaepSHA384

func (m *ModeType) RsaOaepSHA384() ModeType

func (*ModeType) RsaOaepSHA512

func (m *ModeType) RsaOaepSHA512() ModeType

type PaddingType

type PaddingType string

PaddingType padding constants 填充常量

const (
	No    PaddingType = "no"
	Zero  PaddingType = "zero"
	PKCS5 PaddingType = "pkcs5"
	PKCS7 PaddingType = "pkcs7"
)

func (*PaddingType) No

func (p *PaddingType) No() PaddingType

func (*PaddingType) PKCS5

func (p *PaddingType) PKCS5() PaddingType

func (*PaddingType) PKCS7

func (p *PaddingType) PKCS7() PaddingType

func (*PaddingType) Zero

func (p *PaddingType) Zero() PaddingType

Jump to

Keyboard shortcuts

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