cryptobin

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2022 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const PBKDF2Iterations = 10000

PBKDF2Iterations is the default number of iterations for PBKDF2, 100k iterations. Nist recommends at least 10k, 1Passsword uses 100k.

View Source
const PBKDF2SaltSize = 16

PBKDF2SaltSize is the default size of the salt for PBKDF2, 128-bit salt.

Variables

View Source
var (
	ErrNotECPublicKey  = errors.New("key is not a valid ECDSA public key")
	ErrNotECPrivateKey = errors.New("key is not a valid ECDSA private key")
)
View Source
var (
	ErrNotEdPrivateKey = errors.New("key is not a valid Ed25519 private key")
	ErrNotEdPublicKey  = errors.New("key is not a valid Ed25519 public key")
)
View Source
var (
	ErrDataToLarge     = errors.New("message too long for RSA public key size")
	ErrDataLen         = errors.New("data length error")
	ErrDataBroken      = errors.New("data broken, first byte is not zero")
	ErrKeyPairDismatch = errors.New("data is not encrypted by the private key")
	ErrDecryption      = errors.New("decryption error")
)
View Source
var (
	ErrKeyMustBePEMEncoded = errors.New("invalid key: Key must be a PEM encoded PKCS1 or PKCS8 key")
	ErrNotRSAPrivateKey    = errors.New("key is not a valid RSA private key")
	ErrNotRSAPublicKey     = errors.New("key is not a valid RSA public key")
)
View Source
var (
	// 创建私钥默认可用选项
	// HMACHash 目前支持 SHA256 和 SHA1
	Youmark_AES128CBC_SHA256 = youmarkPkcs8.Opts{
		Cipher: youmarkPkcs8.AES128CBC,
		KDFOpts: youmarkPkcs8.PBKDF2Opts{
			SaltSize:       8,
			IterationCount: 2048,
			HMACHash:       crypto.SHA256,
		},
	}

	Youmark_AES192CBC_SHA256 = youmarkPkcs8.Opts{
		Cipher: youmarkPkcs8.AES192CBC,
		KDFOpts: youmarkPkcs8.PBKDF2Opts{
			SaltSize:       8,
			IterationCount: 1000,
			HMACHash:       crypto.SHA256,
		},
	}

	Youmark_AES256CBC_SHA256 = youmarkPkcs8.Opts{
		Cipher: youmarkPkcs8.AES256CBC,
		KDFOpts: youmarkPkcs8.PBKDF2Opts{
			SaltSize:       16,
			IterationCount: 2000,
			HMACHash:       crypto.SHA256,
		},
	}

	Youmark_AES128GCM_SHA256 = youmarkPkcs8.Opts{
		Cipher: youmarkPkcs8.AES128GCM,
		KDFOpts: youmarkPkcs8.PBKDF2Opts{
			SaltSize:       8,
			IterationCount: 2048,
			HMACHash:       crypto.SHA256,
		},
	}

	Youmark_AES192GCM_SHA256 = youmarkPkcs8.Opts{
		Cipher: youmarkPkcs8.AES192GCM,
		KDFOpts: youmarkPkcs8.PBKDF2Opts{
			SaltSize:       8,
			IterationCount: 10000,
			HMACHash:       crypto.SHA256,
		},
	}

	Youmark_AES256GCM_SHA256 = youmarkPkcs8.Opts{
		Cipher: youmarkPkcs8.AES256GCM,
		KDFOpts: youmarkPkcs8.PBKDF2Opts{
			SaltSize:       16,
			IterationCount: 16,
			HMACHash:       crypto.SHA256,
		},
	}

	Youmark_TripleDESCBC_SHA1 = youmarkPkcs8.Opts{
		Cipher: youmarkPkcs8.TripleDESCBC,
		KDFOpts: youmarkPkcs8.PBKDF2Opts{
			SaltSize:       16,
			IterationCount: 16,
			HMACHash:       crypto.SHA1,
		},
	}

	Youmark_AES256CBC_Scrypt = youmarkPkcs8.Opts{
		Cipher: youmarkPkcs8.AES256CBC,
		KDFOpts: youmarkPkcs8.ScryptOpts{
			CostParameter:            1 << 2,
			BlockSize:                8,
			ParallelizationParameter: 1,
			SaltSize:                 16,
		},
	}
)
View Source
var DefaultOpts = &Opts{
	SaltSize:       PBKDF2SaltSize,
	IterationCount: PBKDF2Iterations,
	HMACHash:       "SHA256",
}

默认配置

View Source
var PEMCiphers = map[string]x509.PEMCipher{
	"DESCBC":     x509.PEMCipherDES,
	"DESEDE3CBC": x509.PEMCipher3DES,
	"AES128CBC":  x509.PEMCipherAES128,
	"AES192CBC":  x509.PEMCipherAES192,
	"AES256CBC":  x509.PEMCipherAES256,
}

pem 加密方式

Functions

func AddOidAsn1

func AddOidAsn1(name string, identifier asn1.ObjectIdentifier)

添加 oidAsn1

func AddOidHash

func AddOidHash(name string, value func() hash.Hash)

添加 oidHash

func AddRfc1423Algo

func AddRfc1423Algo(value rfc1423Algo)

添加 rfc1423Algo

func DecryptPEMBlock

func DecryptPEMBlock(block *pem.Block, password []byte) ([]byte, error)

解出 PEM 块

func DecryptPKCS8PrivateKey

func DecryptPKCS8PrivateKey(data, password []byte) ([]byte, error)

解出 PKCS8 密钥 加密方式: AES-128-CBC | AES-192-CBC | AES-256-CBC | DES | 3DES

func EncryptPKCS8PrivateKey

func EncryptPKCS8PrivateKey(
	rand io.Reader,
	blockType string,
	data []byte,
	password []byte,
	alg x509.PEMCipher,
	opts ...interface{},
) (*pem.Block, error)

加密 PKCS8

Types

type Cryptobin

type Cryptobin struct {

	// 错误
	Error error
	// contains filtered or unexported fields
}

*

  • 对称加密 *
  • @create 2022-3-19
  • @author deatil

func FromBase64String

func FromBase64String(data string) Cryptobin

Base64

func FromBytes

func FromBytes(data []byte) Cryptobin

字节

func FromHexString

func FromHexString(data string) Cryptobin

Hex

func FromString

func FromString(data string) Cryptobin

字符

func New

func New() Cryptobin

构造函数

func (Cryptobin) AEADDecrypt added in v1.0.2

func (this Cryptobin) AEADDecrypt() Cryptobin

不通用的解密

func (Cryptobin) AEADEncrypt added in v1.0.2

func (this Cryptobin) AEADEncrypt() Cryptobin

不通用的加密

func (Cryptobin) Aes

func (this Cryptobin) Aes() Cryptobin

Aes

func (Cryptobin) AesCFBDecrypt

func (this Cryptobin) AesCFBDecrypt() Cryptobin

解密

func (Cryptobin) AesCFBEncrypt

func (this Cryptobin) AesCFBEncrypt() Cryptobin

加密

func (Cryptobin) AesECBDecrypt

func (this Cryptobin) AesECBDecrypt() Cryptobin

func (Cryptobin) AesECBEncrypt

func (this Cryptobin) AesECBEncrypt() Cryptobin

func (Cryptobin) AesECBGenerateKey

func (this Cryptobin) AesECBGenerateKey(key []byte) (genKey []byte)

func (Cryptobin) Base64Decode

func (this Cryptobin) Base64Decode(s string) ([]byte, error)

Base64 解码

func (Cryptobin) Base64Encode

func (this Cryptobin) Base64Encode(src []byte) string

Base64 编码

func (Cryptobin) Blowfish added in v1.0.2

func (this Cryptobin) Blowfish(salt ...[]byte) Cryptobin

Blowfish

func (Cryptobin) CBC

func (this Cryptobin) CBC() Cryptobin

CBC

func (Cryptobin) CFB

func (this Cryptobin) CFB() Cryptobin

CFB

func (Cryptobin) CTR

func (this Cryptobin) CTR() Cryptobin

CTR

func (Cryptobin) Cast5 added in v1.0.2

func (this Cryptobin) Cast5() Cryptobin

Cast5

func (Cryptobin) Chacha20 added in v1.0.2

func (this Cryptobin) Chacha20(nonce []byte, counter ...uint32) Cryptobin

Chacha20

func (Cryptobin) Chacha20poly1305 added in v1.0.2

func (this Cryptobin) Chacha20poly1305(nonce []byte, additional []byte) Cryptobin

Chacha20poly1305 nonce is 12 bytes

func (Cryptobin) CipherBlock

func (this Cryptobin) CipherBlock(key []byte) (cipher.Block, error)

Cipher

func (Cryptobin) CipherDecrypt added in v1.0.2

func (this Cryptobin) CipherDecrypt() Cryptobin

解密

func (Cryptobin) CipherEncrypt added in v1.0.2

func (this Cryptobin) CipherEncrypt() Cryptobin

加密

func (Cryptobin) Decrypt

func (this Cryptobin) Decrypt() Cryptobin

解密

func (Cryptobin) Des

func (this Cryptobin) Des() Cryptobin

Des

func (Cryptobin) ECB

func (this Cryptobin) ECB() Cryptobin

ECB

func (Cryptobin) Encrypt

func (this Cryptobin) Encrypt() Cryptobin

加密

func (Cryptobin) FromBase64String

func (this Cryptobin) FromBase64String(data string) Cryptobin

Base64

func (Cryptobin) FromBytes

func (this Cryptobin) FromBytes(data []byte) Cryptobin

字节

func (Cryptobin) FromHexString

func (this Cryptobin) FromHexString(data string) Cryptobin

Hex

func (Cryptobin) FromString

func (this Cryptobin) FromString(data string) Cryptobin

字符

func (Cryptobin) GCM

func (this Cryptobin) GCM(nonce []byte, additional []byte) Cryptobin

GCM

func (Cryptobin) GetConfig

func (this Cryptobin) GetConfig(key string) interface{}

获取配置

func (Cryptobin) GetConfigs

func (this Cryptobin) GetConfigs() map[string]interface{}

获取全部配置

func (Cryptobin) GetData

func (this Cryptobin) GetData() []byte

数据

func (Cryptobin) GetError

func (this Cryptobin) GetError() error

错误信息

func (Cryptobin) GetIv

func (this Cryptobin) GetIv() []byte

向量

func (Cryptobin) GetKey

func (this Cryptobin) GetKey() []byte

密码

func (Cryptobin) GetMode

func (this Cryptobin) GetMode() string

加密方式

func (Cryptobin) GetPadding

func (this Cryptobin) GetPadding() string

补码算法

func (Cryptobin) GetParsedData

func (this Cryptobin) GetParsedData() []byte

解析后的数据

func (Cryptobin) GetType

func (this Cryptobin) GetType() string

加密类型

func (Cryptobin) HexDecode

func (this Cryptobin) HexDecode(s string) ([]byte, error)

Hex 解码

func (Cryptobin) HexEncode

func (this Cryptobin) HexEncode(src []byte) string

Hex 编码

func (Cryptobin) NoPadding

func (this Cryptobin) NoPadding() Cryptobin

不补码

func (Cryptobin) NoParsed

func (this Cryptobin) NoParsed() Cryptobin

不做处理

func (Cryptobin) OFB

func (this Cryptobin) OFB() Cryptobin

OFB

func (Cryptobin) PKCS5Padding

func (this Cryptobin) PKCS5Padding() Cryptobin

PKCS5 补码

func (Cryptobin) PKCS7Padding

func (this Cryptobin) PKCS7Padding() Cryptobin

PKCS7 补码

func (Cryptobin) Padding

func (this Cryptobin) Padding(plainText []byte, blockSize int) []byte

Padding 补码模式

func (Cryptobin) Pkcs5Padding

func (this Cryptobin) Pkcs5Padding(text []byte) []byte

PKCS7Padding的子集,块大小固定为8字节

func (Cryptobin) Pkcs5UnPadding

func (this Cryptobin) Pkcs5UnPadding(src []byte) []byte

func (Cryptobin) Pkcs7Padding

func (this Cryptobin) Pkcs7Padding(text []byte, blockSize int) []byte

明文补码算法

func (Cryptobin) Pkcs7UnPadding

func (this Cryptobin) Pkcs7UnPadding(src []byte) []byte

明文减码算法

func (Cryptobin) RC4 added in v1.0.2

func (this Cryptobin) RC4() Cryptobin

RC4

func (Cryptobin) RsaDecrypt

func (this Cryptobin) RsaDecrypt(password ...string) Cryptobin

RSA 私钥解密 pkcs8 带密码不支持其他工具生成的密钥

func (Cryptobin) RsaEncrypt

func (this Cryptobin) RsaEncrypt() Cryptobin

RSA 公钥加密

func (Cryptobin) RsaPrikeyEncrypt

func (this Cryptobin) RsaPrikeyEncrypt(password ...string) Cryptobin

RSA 私钥加密 pkcs8 带密码不支持其他工具生成的密钥

func (Cryptobin) RsaPubkeyDecrypt

func (this Cryptobin) RsaPubkeyDecrypt() Cryptobin

RSA 公钥解密

func (Cryptobin) SetConfig

func (this Cryptobin) SetConfig(key string, value interface{}) Cryptobin

设置配置

func (Cryptobin) SetIv

func (this Cryptobin) SetIv(data string) Cryptobin

向量

func (Cryptobin) SetKey

func (this Cryptobin) SetKey(data string) Cryptobin

密码

func (Cryptobin) String

func (this Cryptobin) String() string

输出原始字符

func (Cryptobin) Tea added in v1.0.2

func (this Cryptobin) Tea(rounds ...int) Cryptobin

Tea

func (Cryptobin) ToBase64String

func (this Cryptobin) ToBase64String() string

输出Base64

func (Cryptobin) ToBytes

func (this Cryptobin) ToBytes() []byte

输出字节

func (Cryptobin) ToHexString

func (this Cryptobin) ToHexString() string

输出Hex

func (Cryptobin) ToString

func (this Cryptobin) ToString() string

输出字符

func (Cryptobin) TriDes

func (this Cryptobin) TriDes() Cryptobin

TriDes

func (Cryptobin) Twofish added in v1.0.2

func (this Cryptobin) Twofish() Cryptobin

Twofish

func (Cryptobin) UnPadding

func (this Cryptobin) UnPadding(cipherText []byte) []byte

UnPadding 补码模式

func (Cryptobin) WithConfig

func (this Cryptobin) WithConfig(config map[string]interface{}) Cryptobin

配置

func (Cryptobin) WithData

func (this Cryptobin) WithData(data []byte) Cryptobin

设置数据

func (Cryptobin) WithIv

func (this Cryptobin) WithIv(data []byte) Cryptobin

设置向量

func (Cryptobin) WithKey

func (this Cryptobin) WithKey(data []byte) Cryptobin

设置密钥

func (Cryptobin) WithMode

func (this Cryptobin) WithMode(data string) Cryptobin

加密方式

func (Cryptobin) WithPadding

func (this Cryptobin) WithPadding(data string) Cryptobin

补码算法

func (Cryptobin) WithType

func (this Cryptobin) WithType(data string) Cryptobin

加密类型

func (Cryptobin) Xtea added in v1.0.2

func (this Cryptobin) Xtea() Cryptobin

Xtea

func (Cryptobin) ZeroPadding

func (this Cryptobin) ZeroPadding() Cryptobin

Zero 补码

func (Cryptobin) ZerosPadding

func (this Cryptobin) ZerosPadding(text []byte, blockSize int) []byte

数据长度不对齐时使用0填充,否则不填充

func (Cryptobin) ZerosUnPadding

func (this Cryptobin) ZerosUnPadding(src []byte) []byte

type Ecdsa

type Ecdsa struct {

	// 错误
	Error error
	// contains filtered or unexported fields
}

*

  • Ecdsa *
  • @create 2022-4-3
  • @author deatil

func EcdsaFromBase64String

func EcdsaFromBase64String(data string) Ecdsa

Base64

func EcdsaFromBytes

func EcdsaFromBytes(data []byte) Ecdsa

字节

func EcdsaFromHexString

func EcdsaFromHexString(data string) Ecdsa

Hex

func EcdsaFromPrivateKey

func EcdsaFromPrivateKey(key []byte) Ecdsa

私钥

func EcdsaFromPublicKey

func EcdsaFromPublicKey(key []byte) Ecdsa

公钥

func EcdsaFromString

func EcdsaFromString(data string) Ecdsa

字符

func EcdsaGenerateKey

func EcdsaGenerateKey(hash string) Ecdsa

生成密钥 可选 [P521 | P384 | P256 | P224]

func NewEcdsa

func NewEcdsa() Ecdsa

构造函数

func (Ecdsa) Base64Decode

func (this Ecdsa) Base64Decode(s string) ([]byte, error)

Base64 解码

func (Ecdsa) Base64Encode

func (this Ecdsa) Base64Encode(src []byte) string

Base64 编码

func (Ecdsa) CreatePrivateKey

func (this Ecdsa) CreatePrivateKey() Ecdsa

私钥

func (Ecdsa) CreatePublicKey

func (this Ecdsa) CreatePublicKey() Ecdsa

公钥

func (Ecdsa) DataHash

func (this Ecdsa) DataHash(signHash string, data []byte) []byte

签名后数据

func (Ecdsa) FromBase64String

func (this Ecdsa) FromBase64String(data string) Ecdsa

Base64

func (Ecdsa) FromBytes

func (this Ecdsa) FromBytes(data []byte) Ecdsa

字节

func (Ecdsa) FromHexString

func (this Ecdsa) FromHexString(data string) Ecdsa

Hex

func (Ecdsa) FromPrivateKey

func (this Ecdsa) FromPrivateKey(key []byte) Ecdsa

私钥

func (Ecdsa) FromPublicKey

func (this Ecdsa) FromPublicKey(key []byte) Ecdsa

公钥

func (Ecdsa) FromString

func (this Ecdsa) FromString(data string) Ecdsa

字符

func (Ecdsa) GenerateKey

func (this Ecdsa) GenerateKey() Ecdsa

生成密钥

func (Ecdsa) GetData

func (this Ecdsa) GetData() []byte

获取 data

func (Ecdsa) GetError

func (this Ecdsa) GetError() error

获取错误

func (Ecdsa) GetKeyData

func (this Ecdsa) GetKeyData() []byte

获取 keyData

func (Ecdsa) GetParedData

func (this Ecdsa) GetParedData() []byte

获取 paredData

func (Ecdsa) GetPrivateKey

func (this Ecdsa) GetPrivateKey() *ecdsa.PrivateKey

获取 PrivateKey

func (Ecdsa) GetPublicKey

func (this Ecdsa) GetPublicKey() *ecdsa.PublicKey

获取 PublicKey

func (Ecdsa) GetSignHash

func (this Ecdsa) GetSignHash() string

获取 hash 类型

func (Ecdsa) GetVeryed

func (this Ecdsa) GetVeryed() bool

获取验证后情况

func (Ecdsa) HexDecode

func (this Ecdsa) HexDecode(s string) ([]byte, error)

Hex 解码

func (Ecdsa) HexEncode

func (this Ecdsa) HexEncode(src []byte) string

Hex 编码

func (Ecdsa) ParseECPrivateKeyFromPEM

func (this Ecdsa) ParseECPrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error)

解析私钥

func (Ecdsa) ParseECPublicKeyFromPEM

func (this Ecdsa) ParseECPublicKeyFromPEM(key []byte) (*ecdsa.PublicKey, error)

解析公钥

func (Ecdsa) Sign

func (this Ecdsa) Sign(separator ...string) Ecdsa

私钥签名

func (Ecdsa) ToBase64String

func (this Ecdsa) ToBase64String() string

输出Base64

func (Ecdsa) ToBytes

func (this Ecdsa) ToBytes() []byte

输出字节

func (Ecdsa) ToHexString

func (this Ecdsa) ToHexString() string

输出Hex

func (Ecdsa) ToKeyBytes

func (this Ecdsa) ToKeyBytes() []byte

私钥/公钥

func (Ecdsa) ToKeyString

func (this Ecdsa) ToKeyString() string

私钥/公钥

func (Ecdsa) ToString

func (this Ecdsa) ToString() string

输出字符

func (Ecdsa) ToVeryed

func (this Ecdsa) ToVeryed() bool

验证结果

func (Ecdsa) Very

func (this Ecdsa) Very(data []byte, separator ...string) Ecdsa

公钥验证

func (Ecdsa) WithCurve

func (this Ecdsa) WithCurve(hash string) Ecdsa

设置 data 可选 [P521 | P384 | P256 | P224]

func (Ecdsa) WithData

func (this Ecdsa) WithData(data []byte) Ecdsa

设置 data

func (Ecdsa) WithError

func (this Ecdsa) WithError(err error) Ecdsa

设置错误

func (Ecdsa) WithParedData

func (this Ecdsa) WithParedData(data []byte) Ecdsa

设置 paredData

func (Ecdsa) WithPrivateKey

func (this Ecdsa) WithPrivateKey(data *ecdsa.PrivateKey) Ecdsa

设置 PrivateKey

func (Ecdsa) WithPublicKey

func (this Ecdsa) WithPublicKey(data *ecdsa.PublicKey) Ecdsa

设置 PublicKey

func (Ecdsa) WithSignHash

func (this Ecdsa) WithSignHash(data string) Ecdsa

设置 hash 类型

type EdDSA added in v1.0.2

type EdDSA struct {

	// 错误
	Error error
	// contains filtered or unexported fields
}

*

  • EdDSA *
  • @create 2022-4-3
  • @author deatil

func EdDSAFromBase64String added in v1.0.2

func EdDSAFromBase64String(data string) EdDSA

Base64

func EdDSAFromBytes added in v1.0.2

func EdDSAFromBytes(data []byte) EdDSA

字节

func EdDSAFromHexString added in v1.0.2

func EdDSAFromHexString(data string) EdDSA

Hex

func EdDSAFromPrivateKey added in v1.0.2

func EdDSAFromPrivateKey(key []byte) EdDSA

私钥

func EdDSAFromPublicKey added in v1.0.2

func EdDSAFromPublicKey(key []byte) EdDSA

公钥

func EdDSAFromString added in v1.0.2

func EdDSAFromString(data string) EdDSA

字符

func EdDSAGenerateKey added in v1.0.2

func EdDSAGenerateKey() EdDSA

生成密钥

func NewEdDSA added in v1.0.2

func NewEdDSA() EdDSA

构造函数

func (EdDSA) Base64Decode added in v1.0.2

func (this EdDSA) Base64Decode(s string) ([]byte, error)

Base64 解码

func (EdDSA) Base64Encode added in v1.0.2

func (this EdDSA) Base64Encode(src []byte) string

Base64 编码

func (EdDSA) CreatePrivateKey added in v1.0.2

func (this EdDSA) CreatePrivateKey() EdDSA

私钥

func (EdDSA) CreatePublicKey added in v1.0.2

func (this EdDSA) CreatePublicKey() EdDSA

公钥

func (EdDSA) FromBase64String added in v1.0.2

func (this EdDSA) FromBase64String(data string) EdDSA

Base64

func (EdDSA) FromBytes added in v1.0.2

func (this EdDSA) FromBytes(data []byte) EdDSA

字节

func (EdDSA) FromHexString added in v1.0.2

func (this EdDSA) FromHexString(data string) EdDSA

Hex

func (EdDSA) FromPrivateKey added in v1.0.2

func (this EdDSA) FromPrivateKey(key []byte) EdDSA

私钥

func (EdDSA) FromPublicKey added in v1.0.2

func (this EdDSA) FromPublicKey(key []byte) EdDSA

公钥

func (EdDSA) FromString added in v1.0.2

func (this EdDSA) FromString(data string) EdDSA

字符

func (EdDSA) GenerateKey added in v1.0.2

func (this EdDSA) GenerateKey() EdDSA

生成密钥

func (EdDSA) GetData added in v1.0.2

func (this EdDSA) GetData() []byte

获取 data

func (EdDSA) GetError added in v1.0.2

func (this EdDSA) GetError() error

获取错误

func (EdDSA) GetKeyData added in v1.0.2

func (this EdDSA) GetKeyData() []byte

获取 keyData

func (EdDSA) GetParedData added in v1.0.2

func (this EdDSA) GetParedData() []byte

获取 paredData

func (EdDSA) GetPrivateKey added in v1.0.2

func (this EdDSA) GetPrivateKey() ed25519.PrivateKey

获取 PrivateKey

func (EdDSA) GetPublicKey added in v1.0.2

func (this EdDSA) GetPublicKey() ed25519.PublicKey

获取 PublicKey

func (EdDSA) GetVeryed added in v1.0.2

func (this EdDSA) GetVeryed() bool

获取验证后情况

func (EdDSA) HexDecode added in v1.0.2

func (this EdDSA) HexDecode(s string) ([]byte, error)

Hex 解码

func (EdDSA) HexEncode added in v1.0.2

func (this EdDSA) HexEncode(src []byte) string

Hex 编码

func (EdDSA) ParseEdPrivateKeyFromPEM added in v1.0.2

func (this EdDSA) ParseEdPrivateKeyFromPEM(key []byte) (crypto.PrivateKey, error)

解析私钥

func (EdDSA) ParseEdPublicKeyFromPEM added in v1.0.2

func (this EdDSA) ParseEdPublicKeyFromPEM(key []byte) (crypto.PublicKey, error)

解析公钥

func (EdDSA) Sign added in v1.0.2

func (this EdDSA) Sign() EdDSA

私钥签名

func (EdDSA) ToBase64String added in v1.0.2

func (this EdDSA) ToBase64String() string

输出Base64

func (EdDSA) ToBytes added in v1.0.2

func (this EdDSA) ToBytes() []byte

输出字节

func (EdDSA) ToHexString added in v1.0.2

func (this EdDSA) ToHexString() string

输出Hex

func (EdDSA) ToKeyBytes added in v1.0.2

func (this EdDSA) ToKeyBytes() []byte

私钥/公钥

func (EdDSA) ToKeyString added in v1.0.2

func (this EdDSA) ToKeyString() string

私钥/公钥

func (EdDSA) ToString added in v1.0.2

func (this EdDSA) ToString() string

输出字符

func (EdDSA) ToVeryed added in v1.0.2

func (this EdDSA) ToVeryed() bool

验证结果

func (EdDSA) Very added in v1.0.2

func (this EdDSA) Very(data []byte) EdDSA

公钥验证

func (EdDSA) WithData added in v1.0.2

func (this EdDSA) WithData(data []byte) EdDSA

设置 data

func (EdDSA) WithError added in v1.0.2

func (this EdDSA) WithError(err error) EdDSA

设置错误

func (EdDSA) WithParedData added in v1.0.2

func (this EdDSA) WithParedData(data []byte) EdDSA

设置 paredData

func (EdDSA) WithPrivateKey added in v1.0.2

func (this EdDSA) WithPrivateKey(data ed25519.PrivateKey) EdDSA

设置 PrivateKey

func (EdDSA) WithPublicKey added in v1.0.2

func (this EdDSA) WithPublicKey(data ed25519.PublicKey) EdDSA

设置 PublicKey

type Opts

type Opts struct {
	SaltSize       int
	IterationCount int
	HMACHash       string
}

配置

type Rsa

type Rsa struct {

	// 错误
	Error error
	// contains filtered or unexported fields
}

*

  • Rsa 加密 *
  • @create 2021-8-28
  • @author deatil

func NewRsa

func NewRsa() Rsa

构造函数

func RsaFromBase64String

func RsaFromBase64String(data string) Rsa

Base64

func RsaFromBytes

func RsaFromBytes(data []byte) Rsa

字节

func RsaFromHexString

func RsaFromHexString(data string) Rsa

Hex

func RsaFromPKCS1

func RsaFromPKCS1(key []byte) Rsa

Pkcs1

func RsaFromPKCS1WithPassword

func RsaFromPKCS1WithPassword(key []byte, password string) Rsa

Pkcs1WithPassword

func RsaFromPKCS8

func RsaFromPKCS8(key []byte) Rsa

Pkcs8

func RsaFromPKCS8WithPassword

func RsaFromPKCS8WithPassword(key []byte, password string) Rsa

Pkcs8WithPassword

func RsaFromPrivateKey

func RsaFromPrivateKey(key []byte) Rsa

私钥

func RsaFromPrivateKeyWithPassword

func RsaFromPrivateKeyWithPassword(key []byte, password string) Rsa

私钥带密码

func RsaFromPublicKey

func RsaFromPublicKey(key []byte) Rsa

公钥

func RsaFromString

func RsaFromString(data string) Rsa

字符

func RsaFromYoumarkPKCS8WithPassword

func RsaFromYoumarkPKCS8WithPassword(key []byte, password string) Rsa

设置私钥带密码

func RsaGenerateKey

func RsaGenerateKey(bits int) Rsa

生成密钥 bits = 512 | 1024 | 2048 | 4096

func (Rsa) Base64Decode

func (this Rsa) Base64Decode(s string) ([]byte, error)

Base64 解码

func (Rsa) Base64Encode

func (this Rsa) Base64Encode(src []byte) string

Base64 编码

func (Rsa) CreatePKCS1

func (this Rsa) CreatePKCS1() Rsa

PKCS1 私钥

func (Rsa) CreatePKCS1WithPassword

func (this Rsa) CreatePKCS1WithPassword(password string, opts ...string) Rsa

PKCS1 私钥带密码 CreatePKCS1WithPassword("123", "AES256CBC")

func (Rsa) CreatePKCS8

func (this Rsa) CreatePKCS8() Rsa

PKCS8 私钥

func (Rsa) CreatePKCS8WithPassword

func (this Rsa) CreatePKCS8WithPassword(password string, opts ...string) Rsa

PKCS8 私钥带密码 CreatePKCS8WithPassword("123", "AES256CBC", "SHA256")

func (Rsa) CreatePublicKey

func (this Rsa) CreatePublicKey() Rsa

公钥

func (Rsa) CreateYoumarkPKCS8WithPassword

func (this Rsa) CreateYoumarkPKCS8WithPassword(password string, opt ...youmarkPkcs8.Opts) Rsa

创建私钥带密码

func (Rsa) DataHash added in v1.0.2

func (this Rsa) DataHash(signHash string, data []byte) []byte

签名后数据

func (Rsa) Decrypt

func (this Rsa) Decrypt() Rsa

私钥解密

func (Rsa) Encrypt

func (this Rsa) Encrypt() Rsa

公钥加密

func (Rsa) FromBase64String

func (this Rsa) FromBase64String(data string) Rsa

Base64

func (Rsa) FromBytes

func (this Rsa) FromBytes(data []byte) Rsa

字节

func (Rsa) FromHexString

func (this Rsa) FromHexString(data string) Rsa

Hex

func (Rsa) FromPKCS1

func (this Rsa) FromPKCS1(key []byte) Rsa

Pkcs1

func (Rsa) FromPKCS1WithPassword

func (this Rsa) FromPKCS1WithPassword(key []byte, password string) Rsa

Pkcs1WithPassword

func (Rsa) FromPKCS8

func (this Rsa) FromPKCS8(key []byte) Rsa

Pkcs8

func (Rsa) FromPKCS8WithPassword

func (this Rsa) FromPKCS8WithPassword(key []byte, password string) Rsa

Pkcs8WithPassword

func (Rsa) FromPrivateKey

func (this Rsa) FromPrivateKey(key []byte) Rsa

私钥

func (Rsa) FromPrivateKeyWithPassword

func (this Rsa) FromPrivateKeyWithPassword(key []byte, password string) Rsa

私钥带密码

func (Rsa) FromPublicKey

func (this Rsa) FromPublicKey(key []byte) Rsa

公钥

func (Rsa) FromString

func (this Rsa) FromString(data string) Rsa

字符

func (Rsa) FromYoumarkPKCS8WithPassword

func (this Rsa) FromYoumarkPKCS8WithPassword(key []byte, password string) Rsa

设置私钥带密码

func (Rsa) GenerateKey

func (this Rsa) GenerateKey(bits int) Rsa

生成密钥 bits = 512 | 1024 | 2048 | 4096

func (Rsa) GetData

func (this Rsa) GetData() []byte

获取 data

func (Rsa) GetError

func (this Rsa) GetError() error

获取错误

func (Rsa) GetKeyData

func (this Rsa) GetKeyData() []byte

获取 keyData

func (Rsa) GetParedData

func (this Rsa) GetParedData() []byte

获取 paredData

func (Rsa) GetPrivateKey

func (this Rsa) GetPrivateKey() *rsa.PrivateKey

获取 PrivateKey

func (Rsa) GetPublicKey

func (this Rsa) GetPublicKey() *rsa.PublicKey

获取 PublicKey

func (Rsa) GetSignHash

func (this Rsa) GetSignHash() string

获取 hash 类型

func (Rsa) GetVeryed

func (this Rsa) GetVeryed() bool

获取验证后情况

func (Rsa) HashType added in v1.0.2

func (this Rsa) HashType(signHash string) crypto.Hash

签名

func (Rsa) HexDecode

func (this Rsa) HexDecode(s string) ([]byte, error)

Hex 解码

func (Rsa) HexEncode

func (this Rsa) HexEncode(src []byte) string

Hex 编码

func (Rsa) PSSSign added in v1.0.2

func (this Rsa) PSSSign(opts ...rsa.PSSOptions) Rsa

私钥签名 常用为: PS256[SHA256] | PS384[SHA384] | PS512[SHA512]

func (Rsa) PSSVery added in v1.0.2

func (this Rsa) PSSVery(data []byte, opts ...rsa.PSSOptions) Rsa

公钥验证 使用原始数据[data]对比签名后数据

func (Rsa) ParseRSAPKCS8PrivateKeyFromPEMWithPassword

func (this Rsa) ParseRSAPKCS8PrivateKeyFromPEMWithPassword(key []byte, password string) (*rsa.PrivateKey, error)

解析 PKCS8 带密码的私钥

func (Rsa) ParseRSAPrivateKeyFromPEM

func (this Rsa) ParseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error)

解析 PKCS1 / PKCS8 私钥

func (Rsa) ParseRSAPrivateKeyFromPEMWithPassword

func (this Rsa) ParseRSAPrivateKeyFromPEMWithPassword(key []byte, password string) (*rsa.PrivateKey, error)

解析 PKCS1 带密码的私钥

func (Rsa) ParseRSAPublicKeyFromPEM

func (this Rsa) ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error)

解析 PKCS1 / PKCS8 公钥

func (Rsa) PriKeyEncrypt

func (this Rsa) PriKeyEncrypt() Rsa

私钥加密

func (Rsa) PubKeyDecrypt

func (this Rsa) PubKeyDecrypt() Rsa

公钥解密

func (Rsa) Sign

func (this Rsa) Sign() Rsa

私钥签名

func (Rsa) ToBase64String

func (this Rsa) ToBase64String() string

输出Base64

func (Rsa) ToBytes

func (this Rsa) ToBytes() []byte

输出字节

func (Rsa) ToHexString

func (this Rsa) ToHexString() string

输出Hex

func (Rsa) ToKeyBytes

func (this Rsa) ToKeyBytes() []byte

私钥/公钥

func (Rsa) ToKeyString

func (this Rsa) ToKeyString() string

私钥/公钥

func (Rsa) ToString

func (this Rsa) ToString() string

输出字符

func (Rsa) ToVeryed

func (this Rsa) ToVeryed() bool

验证结果

func (Rsa) Very

func (this Rsa) Very(data []byte) Rsa

公钥验证 使用原始数据[data]对比签名后数据

func (Rsa) WithData

func (this Rsa) WithData(data []byte) Rsa

设置 data

func (Rsa) WithError

func (this Rsa) WithError(err error) Rsa

设置错误

func (Rsa) WithParedData

func (this Rsa) WithParedData(data []byte) Rsa

设置 paredData

func (Rsa) WithPrivateKey

func (this Rsa) WithPrivateKey(data *rsa.PrivateKey) Rsa

设置 PrivateKey

func (Rsa) WithPublicKey

func (this Rsa) WithPublicKey(data *rsa.PublicKey) Rsa

设置 PublicKey

func (Rsa) WithSignHash

func (this Rsa) WithSignHash(data string) Rsa

设置 hash 类型

Jump to

Keyboard shortcuts

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