zdpgo_password

package module
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2022 License: MIT Imports: 20 Imported by: 3

README

Golang加密解密框架

超简单的Golang密码加密解密工具

项目地址:https://github.com/zhangdapeng520/zdpgo_password

功能清单

  • 常用HASH加密
  • AES加密解密
  • RSA加密解密
  • ECC加密解密

版本历史

  • v0.1.0 2022/01/01
  • v0.1.1 2022/03/02 AES加密和RSA加密
  • v1.1.0 2022/04/01 ECC加密
  • v1.1.1 2022/04/01 移除第三方依赖
  • v1.1.2 2022/04/01 项目结构优化
  • v1.1.3 2022/04/07 日志组件升级
  • v1.1.4 2022/04/07 AES的GCM加密模式便捷方法
  • v1.1.5 2022/04/09 新增不使用Key的MD5加密和校验方法
  • v1.1.6 2022/04/01 新增URL编码和解码
  • v1.1.7 2022/04/01 新增HEX编码和解码
  • v1.1.8 2022/05/04 新增:文件加密解密
  • v1.1.9 2022/05/04 优化:文件加密解密
  • v1.2.0 2022/06/02 优化:ECC加密解密
  • v1.2.1 2022/06/06 新增:ECC支持指定公钥和私钥
  • v1.2.2 2022/06/06 新增:ECC支持获取公钥和私钥
  • v1.2.3 2022/06/06 优化:多个ECC对象支持共用公钥和私钥
  • v1.2.4 2022/06/11 新增:不使用base64编码的ECC加密方式

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exists added in v1.2.0

func Exists(path string) bool

Exists 判断所给路径文件/文件夹是否存在

Types

type Config added in v1.2.0

type Config struct {
	Debug       bool            // 是否为debug模式
	LogFilePath string          // 日志路径
	Aes         aes.AesConfig   `yaml:"aes" json:"aes"`   // AES加密核心配置
	Rsa         rsa.RsaConfig   `yaml:"rsa" json:"rsa"`   // RSA加密核心配置
	Hash        hash.HashConfig `yaml:"hash" json:"hash"` // HASH加密核心配置
	KeyPath     string          `yaml:"key_path" json:"key_path"`
	EccKey      Key             `yaml:"ecc_key" json:"ecc_key"` // ECC秘钥
}

Config 密码配置对象

type DecryptInterface added in v1.1.2

type DecryptInterface interface {
	Decrypt(data []byte) ([]byte, error) // 密码解密
}

DecryptInterface 密码解密接口

type DecryptStringInterface added in v1.1.2

type DecryptStringInterface interface {
	DecryptString(data string) (string, error) // 密码解密
}

DecryptStringInterface 字符串解密接口

type Ecc added in v1.1.0

type Ecc struct {
	Config *Config
	Log    *zdpgo_log.Log
	// contains filtered or unexported fields
}

func (*Ecc) Decrypt added in v1.1.0

func (e *Ecc) Decrypt(cryptData []byte) ([]byte, error)

Decrypt 解密数据

func (*Ecc) DecryptByPrivateKey added in v1.2.1

func (e *Ecc) DecryptByPrivateKey(cryptData, privateKey []byte) ([]byte, error)

DecryptByPrivateKey 通过特定的私钥进行解密

func (*Ecc) DecryptString added in v1.1.0

func (e *Ecc) DecryptString(cryptData string) (string, error)

DecryptString 解密字符串

func (*Ecc) DecryptStringNoBase64 added in v1.2.4

func (e *Ecc) DecryptStringNoBase64(cryptData string) (string, error)

func (*Ecc) Encrypt added in v1.1.0

func (e *Ecc) Encrypt(data []byte) ([]byte, error)

Encrypt 加密数据

func (*Ecc) EncryptByPublicKey added in v1.2.1

func (e *Ecc) EncryptByPublicKey(data, publicKey []byte) ([]byte, error)

EncryptByPublicKey 指定公钥进行数据加密

func (*Ecc) EncryptString added in v1.1.0

func (e *Ecc) EncryptString(data string) (string, error)

EncryptString 加密字符串

func (*Ecc) EncryptStringNoBase64 added in v1.2.4

func (e *Ecc) EncryptStringNoBase64(data string) (string, error)

func (*Ecc) GetKey added in v1.2.2

func (e *Ecc) GetKey() ([]byte, []byte, error)

GetKey 生成ECC的私钥 @return 私钥,公钥,错误信息

func (*Ecc) InitKey added in v1.2.0

func (e *Ecc) InitKey() error

InitKey 初始化key

func (*Ecc) SetKeyData added in v1.2.0

func (e *Ecc) SetKeyData(privateKeyFilePath, publicKeyFilePath string) error

SetKeyData 设置公钥和私钥数据

func (*Ecc) Sign added in v1.2.0

func (e *Ecc) Sign(data []byte) ([]byte, error)

Sign 对数据进行签名

func (*Ecc) Verify added in v1.2.0

func (e *Ecc) Verify(originData, signData []byte) bool

Verify 对数据进行校验

type EncryptInterface added in v1.1.2

type EncryptInterface interface {
	Encrypt(data []byte) ([]byte, error) // 密码加密
}

EncryptInterface 密码加密接口

type EncryptStringInterface added in v1.1.2

type EncryptStringInterface interface {
	EncryptString(data string) (string, error) // 密码加密
}

EncryptStringInterface 字符串加密接口

type Key added in v1.2.0

type Key struct {
	PrivateKey         []byte `yaml:"private_key" json:"private_key"`
	PublicKey          []byte `yaml:"public_key" json:"public_key"`
	PrivateKeyPrefix   string `yaml:"private_key_prefix" json:"private_key_prefix"`
	PublicKeyPrefix    string `yaml:"public_key_prefix" json:"public_key_prefix"`
	PrivateKeyFileName string `yaml:"private_key_file_name" json:"private_key_file_name"`
	PublicKeyFileName  string `yaml:"public_key_file_name" json:"public_key_file_name"`
}

type Password added in v1.1.2

type Password struct {
	Log    *zdpgo_log.Log // 日志对象
	Config *Config        // 配置对象
	Aes    *aes2.Aes      // AES加密核心对象
	Rsa    *rsa2.Rsa      // RSA加密核心对象
	Hash   *hash2.Hash    // HASH加密核心对象
	Ecc    *Ecc           // ECC加密核心对象
	Url    *zurl.Url      // URL编码解码核心对象
	Hex    *hex.Hex       // 十六进制编码解码
}

Password 密码加密核心对象

func New

func New() *Password

func NewWithConfig added in v1.2.3

func NewWithConfig(config *Config) *Password

NewWithConfig 创建加密对象

func (*Password) DecryptFile added in v1.1.8

func (p *Password) DecryptFile(filePath string) error

DecryptFile 解密文件

func (*Password) DecryptFileNoChangeName added in v1.1.9

func (p *Password) DecryptFileNoChangeName(filePath string) error

DecryptFileNoChangeName 解密文件且不修改文件名

func (*Password) DecryptFileWithEncryptName added in v1.1.8

func (p *Password) DecryptFileWithEncryptName(encryptFilePath string) error

DecryptFileWithEncryptName 根据加密文件名解密文件

func (*Password) EncryptFile added in v1.1.8

func (p *Password) EncryptFile(filePath string) error

EncryptFile 加密文件

func (*Password) EncryptFileNoChangeName added in v1.1.9

func (p *Password) EncryptFileNoChangeName(filePath string) error

EncryptFileNoChangeName 加密文件且不修改文件名

func (*Password) GetEcc added in v1.2.0

func (p *Password) GetEcc() *Ecc

GetEcc 获取ECC加密对象

func (*Password) GetEncryptFileName added in v1.1.9

func (p *Password) GetEncryptFileName(filePath string) (encryptFilePath string, encryptFileName string, err error)

GetEncryptFileName 获取加密文件名 @return decryptFilePath 加密文件路径 @return decryptFileName 加密文件文件名

func (*Password) ReadEncryptFile added in v1.1.9

func (p *Password) ReadEncryptFile(filePath string) (data []byte, err error)

ReadEncryptFile 读取加密文件的内容

type PasswordInterface added in v1.1.2

type PasswordInterface interface {
	EncryptInterface
	DecryptInterface
}

PasswordInterface 字节数据密码接口

type PasswordStringInterface added in v1.1.2

type PasswordStringInterface interface {
	EncryptStringInterface
	DecryptStringInterface
}

PasswordStringInterface 字符串数据密码接口

Directories

Path Synopsis
core
hex
examples
z01_hash command
z02_aes command
z03_rsa command
z04_ecc command
libs
blake256
Package blake256 implements BLAKE-256 and BLAKE-224 hash functions (SHA-3 candidate).
Package blake256 implements BLAKE-256 and BLAKE-224 hash functions (SHA-3 candidate).
pbkdf2
Package pbkdf2 implements the key derivation function PBKDF2 as defined in RFC 2898 / PKCS #5 v2.0.
Package pbkdf2 implements the key derivation function PBKDF2 as defined in RFC 2898 / PKCS #5 v2.0.

Jump to

Keyboard shortcuts

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