wind

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2025 License: MIT Imports: 17 Imported by: 0

README

🌪️ wind - 加密与安全工具库 🌪️

轻量级 | 高性能 | 安全可靠
支持 RSAAES 加密、解密、签名及验证功能。

build license version


🚀 项目简介

wind 是一款基于 Go 语言开发的现代化加密工具库,专注于数据安全,提供简单易用的接口和高性能加密能力,适合各种安全需求场景。

🌟 核心特性

✅ 支持 RSA 和 AES 多种加密算法。
✅ 提供签名与验证,确保数据完整性与合法性。
✅ 支持证书生成与管理,方便密钥管理。
✅ 高度可配置,支持自定义填充和编码格式。
✅ 兼容多平台,满足跨平台开发需求。


🔑 安装与快速开始

1️⃣ 安装
go get github.com/username/wind

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AbstractMode

type AbstractMode interface {
	Encrypt(plainText, key, iv, nonce, additionalData []byte, paddingType int) ([]byte, error)
	Decrypt(cipherText, key, iv, nonce, additionalData []byte, paddingType int) ([]byte, error)
}

type Aes

type Aes struct {
	Mode           string
	Key            string
	Iv             string
	Nonce          string
	Padding        PaddingEnum
	AdditionalData string
}

func (*Aes) AddMode

func (a *Aes) AddMode(modeName string, mode AbstractMode) error

func (*Aes) Decrypt

func (a *Aes) Decrypt(cipherText string, format FormatEnum) (plainByte []byte, err error)

func (*Aes) Encrypt

func (a *Aes) Encrypt(plainText []byte, format FormatEnum) (ciphertext string, err error)

type AesMode

type AesMode func(plainText, key, iv []byte, paddingType int) ([]byte, error)

type CryptoPaddingEnum

type CryptoPaddingEnum string
const (
	PKCS1v15Padding CryptoPaddingEnum = "PKCS1v15"
	OAEPPadding     CryptoPaddingEnum = "OAEP"
)

type FormatEnum

type FormatEnum string
const (
	Str          FormatEnum = "str"
	Hex          FormatEnum = "hex"
	Base64       FormatEnum = "base64"
	Base64Url    FormatEnum = "base64url"
	Base64RawUrl FormatEnum = "base64rawUrl"
)

type HashTypeEnum

type HashTypeEnum string
const (
	Sha1   HashTypeEnum = "SHA1"
	Sha224 HashTypeEnum = "SHA224"
	Sha256 HashTypeEnum = "SHA256"
	Sha384 HashTypeEnum = "SHA384"
	Sha512 HashTypeEnum = "SHA512"
)

type KeyFormatEnum

type KeyFormatEnum string
const (
	PKCS1 KeyFormatEnum = "PKCS1" // 格式: RSA PRIVATE KEY
	PKCS8 KeyFormatEnum = "PKCS8" // 格式: PRIVATE KEY
)

type PaddingEnum

type PaddingEnum int
const (
	NoPadding PaddingEnum = 1
	PKCS5     PaddingEnum = 2
	PKCS7     PaddingEnum = 3
	ISO10126  PaddingEnum = 4
	Zero      PaddingEnum = 5
	ANISx923  PaddingEnum = 6
)

type PemTypeEnum

type PemTypeEnum string
const (
	PrivatePKCS1Pem PemTypeEnum = "RSA PRIVATE KEY"
	PublicPKCS1Pem  PemTypeEnum = "RSA PUBLIC KEY"
	PrivatePKCS8Pem PemTypeEnum = "PRIVATE KEY"
	PublicPKCS8Pem  PemTypeEnum = "PUBLIC KEY"
)

func PrivatePemList

func PrivatePemList() []PemTypeEnum

func PublicPemList

func PublicPemList() []PemTypeEnum

type Rsa

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

func (*Rsa) BuildCert

func (r *Rsa) BuildCert(template, parentCert *x509.Certificate, parentPrivateKey *rsa.PrivateKey) error

BuildCert generates a certificate from a template and signs it with the parent's private key.

func (*Rsa) Decrypt

func (r *Rsa) Decrypt(ciphertext string, padding CryptoPaddingEnum, hashType HashTypeEnum, format FormatEnum, label []byte) (plainText []byte, err error)

Decrypt decrypts the given ciphertext using RSA private key with specified padding, hash type, and format. It returns the plaintext or an error if any issue occurs during decryption.

func (*Rsa) Encrypt

func (r *Rsa) Encrypt(plainText []byte, padding CryptoPaddingEnum, hashType HashTypeEnum, format FormatEnum, label []byte) (ciphertext string, err error)

Encrypt encrypts the given plaintext using RSA public key with specified padding, hash type, and format. It returns the ciphertext as a string or an error if any issue occurs during encryption.

func (*Rsa) GenSerialNumber

func (r *Rsa) GenSerialNumber() *big.Int

GenSerialNumber generates a random serial number for the certificate.

func (*Rsa) GenerateKey

func (r *Rsa) GenerateKey(bits RsaKeySizeEnum) error

GenerateKey generates a new RSA key pair with the specified key size.

func (*Rsa) GetCert

func (r *Rsa) GetCert() *x509.Certificate

GetCert returns the X.509 certificate.

func (*Rsa) GetCertStr

func (r *Rsa) GetCertStr() (cert string, err error)

GetCertStr retrieves the certificate in PEM format.

func (*Rsa) GetKeyStr

func (r *Rsa) GetKeyStr(format KeyFormatEnum) (priKey, pubKey string, err error)

GetKeyStr retrieves the private and public keys in PEM format.

func (*Rsa) GetPrivate

func (r *Rsa) GetPrivate() *rsa.PrivateKey

GetPrivate returns the RSA private key.

func (*Rsa) GetPublic

func (r *Rsa) GetPublic() *rsa.PublicKey

GetPublic returns the RSA public key.

func (*Rsa) LoadCert

func (r *Rsa) LoadCert(certPEM []byte) error

LoadCert loads an RSA certificate from a PEM-encoded byte slice.

func (*Rsa) LoadCertByFile

func (r *Rsa) LoadCertByFile(certFile string) error

LoadCertByFile loads an RSA certificate from a PEM-encoded file.

func (*Rsa) LoadCertByRaw added in v1.0.2

func (r *Rsa) LoadCertByRaw(raw string, format FormatEnum) error

LoadCertByRaw Load RSA certificate from raw data.

func (*Rsa) LoadKey

func (r *Rsa) LoadKey(keyPem []byte) error

LoadKey loads an RSA private/public key pair from a PEM-encoded byte slice.

func (*Rsa) LoadKeyByFile

func (r *Rsa) LoadKeyByFile(keyFile string) error

LoadKeyByFile loads an RSA private/public key pair from a PEM-encoded file.

func (*Rsa) SaveCert

func (r *Rsa) SaveCert(dir, filename string) error

SaveCert saves the certificate to a file in PEM format.

func (*Rsa) SaveKey

func (r *Rsa) SaveKey(format KeyFormatEnum, dir, filename string) (err error)

SaveKey saves the private and public keys to files in PEM format.

func (*Rsa) Sign

func (r *Rsa) Sign(msg []byte, signType SignTypeEnum, hashType HashTypeEnum, format FormatEnum, opts *rsa.PSSOptions) (ciphertext string, err error)

Sign signs a message using the private key, the specified signing type, hash type, and format.

func (*Rsa) VerifySign

func (r *Rsa) VerifySign(msg []byte, ciphertext string, signType SignTypeEnum, hashType HashTypeEnum, format FormatEnum, opts *rsa.PSSOptions) (err error)

VerifySign verifies the signature of a message using the public key, the signature, and the specified hash type and format.

type RsaKeySizeEnum

type RsaKeySizeEnum int
const (
	RSA2048 RsaKeySizeEnum = 2048
	RSA3072 RsaKeySizeEnum = 3072
	RSA4096 RsaKeySizeEnum = 4096
)

type SignTypeEnum

type SignTypeEnum string
const (
	PKCS1v15 SignTypeEnum = "PKCS1v15"
	PSS      SignTypeEnum = "PSS"
)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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