crypto

package
v0.0.0-...-95be442 Latest Latest
Warning

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

Go to latest
Published: May 3, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// RSAAlgorithmSign RSA签名算法
	RSAAlgorithmSign = crypto.SHA256
)

Variables

This section is empty.

Functions

func CryptPassword

func CryptPassword(password, salt string) string

CryptPassword 加密密码

func GenRandomString

func GenRandomString(length int, specialChar string) string

GenRandomString 生成随机字符串 length 生成长度 specialChar 是否生成特殊字符

func GetMD5

func GetMD5(text string) string

GetMD5 生成32位MD5

func MarshalPKCS8PrivateKey

func MarshalPKCS8PrivateKey(key *rsa.PrivateKey) []byte

MarshalPKCS8PrivateKey 私钥解析

func NewRSAFile

func NewRSAFile(pubKeyFilename, priKeyFilename string, keyLength int) error

NewRSAFile 生成密钥对文件 pubKeyFilename: 公钥文件名 priKeyFilename: 私钥文件名 keyLength: 密钥长度

func NewRSAString

func NewRSAString(keyLength int) (string, string, error)

NewRSAString 生成密钥对字符串 keyLength 密钥的长度

func ReadRSAKeyPair

func ReadRSAKeyPair(pubKeyFilename, priKeyFilename string) ([]byte, []byte, error)

ReadRSAKeyPair 读取RSA密钥对 pubKeyFilename: 公钥文件名称 priKeyFilename: 私钥文件名

func WriteRSAKeyPair

func WriteRSAKeyPair(publicKeyWriter, privateKeyWriter io.Writer, keyLength int) error

WriteRSAKeyPair 生成RSA密钥对

Types

type GoAES

type GoAES struct {
	Key []byte
}

GoAES 加密

func NewGoAES

func NewGoAES(key []byte) *GoAES

NewGoAES 返回GoAES

func (*GoAES) Decrypt

func (a *GoAES) Decrypt(encrypted []byte) ([]byte, error)

Decrypt 解密数据

func (*GoAES) Encrypt

func (a *GoAES) Encrypt(origData []byte) ([]byte, error)

Encrypt 加密数据

type GoRSA

type GoRSA struct {
	PublicKey  *rsa.PublicKey
	PrivateKey *rsa.PrivateKey
}

GoRSA RSA加密解密

func NewGoRSA

func NewGoRSA(pubKeyFilename, priKeyFilename string) (*GoRSA, error)

NewGoRSA 初始化 GoRSA对象

func (*GoRSA) PrivateDecrypt

func (r *GoRSA) PrivateDecrypt(encrypted []byte) ([]byte, error)

PrivateDecrypt 私钥解密

func (*GoRSA) PublicEncrypt

func (r *GoRSA) PublicEncrypt(data []byte) ([]byte, error)

PublicEncrypt 公钥加密

func (*GoRSA) Sign

func (r *GoRSA) Sign(data string) (string, error)

Sign 数据进行签名

func (*GoRSA) Verify

func (r *GoRSA) Verify(data string, sign string) error

Verify 数据验证签名

Jump to

Keyboard shortcuts

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