cryptogy

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: LGPL-3.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMd5Password

func CreateMd5Password(password string) string

func CreatePassword

func CreatePassword(password string) string

func CreateToken

func CreateToken(prefix []byte, tailsize int) string

func GetPasswordChanges

func GetPasswordChanges(password string) map[string]any

func Md5

func Md5(data string) string

func Md5File

func Md5File(filename string) (string, error)

Md5File 计算文件的md5哈希值

func Md5Sum

func Md5Sum(data string) string

Md5Sum 计算md5哈希值

func NewSerialNo

func NewSerialNo(n byte) string

func NewTimeSerialNo

func NewTimeSerialNo(n byte, t time.Time) string

func PKCS5Padding

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

func PKCS5Unpadding

func PKCS5Unpadding(origData []byte) []byte

func PKCS7Padding

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

func PKCS7Unpadding

func PKCS7Unpadding(origData []byte) []byte

func RandSalt

func RandSalt(size int) string

RandSalt 产生随机salt

func VerifyPassword

func VerifyPassword(plainText, cipherText string) bool

func ZeroPadding

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

func ZeroUnpadding

func ZeroUnpadding(origData []byte) []byte

Types

type AESCipher

type AESCipher struct {
	Padding   PaddingFunc
	Unpadding UnpaddingFunc
	cipher.Block
	// contains filtered or unexported fields
}

AES加密,支持模式CBC、CFB、CTR、OFB,不支持ECB和GCM 其中CBC模式一般需要填充,用法: c.SetPaddingFunc("PKCS5")

func NewAESCipher

func NewAESCipher(mode string, key []byte) (*AESCipher, error)

func (*AESCipher) Decrypt

func (c *AESCipher) Decrypt(cipherText []byte) ([]byte, error)

func (*AESCipher) Encrypt

func (c *AESCipher) Encrypt(origData []byte) ([]byte, error)

func (*AESCipher) GetDecrypter

func (c *AESCipher) GetDecrypter() cipher.BlockMode

func (*AESCipher) GetEncrypter

func (c *AESCipher) GetEncrypter() cipher.BlockMode

func (*AESCipher) GetStream

func (c *AESCipher) GetStream(isDecrypt bool) cipher.Stream

func (*AESCipher) SetPaddingFunc

func (c *AESCipher) SetPaddingFunc(name string)

type ICipher

type ICipher interface {
	CreatePassword(plainText string) string
	VerifyPassword(plainText, cipherText string) bool
}

func Cipher

func Cipher() ICipher

type MacHash

type MacHash struct {
	// contains filtered or unexported fields
}

MacHash 例如 NewMacHash(sha256.New).SetKey("nonce")

func NewMacHash

func NewMacHash(creator NewHashFunc) *MacHash

func (MacHash) MacSum

func (h MacHash) MacSum(text string) []byte

func (*MacHash) SetKey

func (h *MacHash) SetKey(key string) *MacHash

func (MacHash) Sign

func (h MacHash) Sign(text string) string

func (MacHash) Verify

func (h MacHash) Verify(text, hashed string) bool

type NewHashFunc

type NewHashFunc func() hash.Hash

type PaddingFunc

type PaddingFunc func(cipherText []byte, blockSize int) []byte

type RSACipher

type RSACipher struct {
	// contains filtered or unexported fields
}

RSA加密,支持模式PKCS#1 v1.5,不支持OAEP/PSS 用法: NewRSACipher(privKey, pubKey).Sign(crypto.SHA256, []byte("hello world"))

func NewRSACipher

func NewRSACipher(privKey, pubKey string) RSACipher

func (RSACipher) Decrypt

func (c RSACipher) Decrypt(cipherText []byte) ([]byte, error)

解密

func (RSACipher) Encrypt

func (c RSACipher) Encrypt(origData []byte) ([]byte, error)

加密

func (RSACipher) GetBlock

func (c RSACipher) GetBlock(key []byte, errmsg string) (*pem.Block, error)

解密pem格式的公钥/私钥

func (RSACipher) GetPrivateKey

func (c RSACipher) GetPrivateKey() (*rsa.PrivateKey, error)

func (RSACipher) GetPublicKey

func (c RSACipher) GetPublicKey() (*rsa.PublicKey, error)

func (RSACipher) Sign

func (c RSACipher) Sign(hash crypto.Hash, msg []byte) ([]byte, error)

签名

func (RSACipher) Verify

func (c RSACipher) Verify(hash crypto.Hash, msg, sig []byte) error

校验

type SaltPassword

type SaltPassword struct {
	*MacHash
	// contains filtered or unexported fields
}

SaltPassword 带salt值的sha256密码哈希

func NewSaltPassword

func NewSaltPassword(len int, sep string) *SaltPassword

func (*SaltPassword) CreatePassword

func (p *SaltPassword) CreatePassword(plainText string) string

CreatePassword 设置密码

func (*SaltPassword) VerifyPassword

func (p *SaltPassword) VerifyPassword(plainText, cipherText string) bool

VerifyPassword 校验密码

type UnpaddingFunc

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

Jump to

Keyboard shortcuts

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