encrypt

package
v0.0.0-...-46283b3 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

README

添加一些加密解密方法,方便日常使用,3edsc日常跟Java交互用的比较多

	keystr := "4nQbu你好吗"
	body := "430123211161816"
	str, _ := encrypt.F新建3Desc加解密(keystr).F加密信息(body)
	fmt.Println("str2222;", str)
	str, _ = encrypt.F新建3Desc加解密(keystr).F解密信息(str)
	fmt.Println("str2222;", str)

	打印结果:
	str2222; 1b982a18f507612fcc4579f4b0ee7b24
	str2222; 430123211161816

Documentation

Overview

* @Description: gomall * @Author: ylf * @Date: 2025-03-04 17:26:33 * @LastEditTime: 2025-03-04 17:31:08 * @LastEditors: ylf * @FilePath: \ltool\encrypt\rsa.go

Index

Constants

View Source
const (
	V请求方法_CBC = "CBC"
	V请求方法_CFB = "CFB"
	V请求方法_ECB = "ECB"

	V加解密方式_base64 = "base64"
	V加解密方式_hex    = "hex"

	V填充方式_pkcs5Padding = "pkcs5Padding"
	V填充方式_pkcs7Padding = "pkcs7Padding"
)
View Source
const (
	PEM_BEGIN = "-----BEGIN RSA PRIVATE KEY-----\n"
	PEM_END   = "\n-----END RSA PRIVATE KEY-----"
)

Variables

This section is empty.

Functions

func DeCryptBlocks

func DeCryptBlocks(dst, src []byte, block cipher.Block)

func EnCryptBlocks

func EnCryptBlocks(encryptData, src []byte, block cipher.Block)

func FRsa解密

func FRsa解密(tk, 私钥 string) (str string, err error)

func FmtMd5

func FmtMd5(inter ...interface{}) string

func F处理密钥

func F处理密钥(keystr string) (genKey []byte)

func F处理密钥格式

func F处理密钥格式(key ...string) []byte

func F拼接参数

func F拼接参数(inter ...interface{}) (key string)

func F按双划线切割字符串

func F按双划线切割字符串(theme, 切分符 string) (arr []string)

如果没有__,那么就返回全部跟一个空

func F是否包含中文

func F是否包含中文(str string) bool

func F生成公私钥

func F生成公私钥(name string, 长度 ...int)

func F私钥加上前后缀

func F私钥加上前后缀(privateKey string) string

func F获取加盐密码

func F获取加盐密码(s string) string

func F解析rsa私钥

func F解析rsa私钥(privateKey string) (*rsa.PrivateKey, error)

func F读取公钥证书文件

func F读取公钥证书文件(pt string) (str string, err error)

读取公钥cer文件解析成公钥

func GenRsaKey

func GenRsaKey(bits int, name string) error

func Md5

func Md5(s string) string

md5自动加盐...之前的密码就不行啦

func Md5Byte

func Md5Byte(by []byte) string

func PKCS7Padding

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

func PKCS7UnPadding

func PKCS7UnPadding(src []byte) []byte

func Rsa2签名

func Rsa2签名(signContent string, privateKey string, hash crypto.Hash) string

func SaltMd5

func SaltMd5(s string) string

md5自动加盐,这个盐可以自行设置,默认gomall,初始化后切勿修改!

func SplitByLength

func SplitByLength(str string, length int) []string

Types

type F设置方法

type F设置方法 struct {
	// contains filtered or unexported fields
}

func F新建ase设置方法

func F新建ase设置方法(f func(*N新ase)) *F设置方法

func F设置偏移量

func F设置偏移量(s string) *F设置方法

func F设置加密加解密方式

func F设置加密加解密方式(s string) *F设置方法

func F设置加密填充方式

func F设置加密填充方式(s string) *F设置方法

func F设置加密请求方法

func F设置加密请求方法(s string) *F设置方法

func F设置密钥

func F设置密钥(s string) *F设置方法

type I设置接口

type I设置接口 interface {
	// contains filtered or unexported methods
}

type N新ase

type N新ase struct {
	ASE密钥        []byte
	V偏移量         []byte
	V加密块         cipher.Block
	V请求方法, V填充方式 string //支持CBC CFB ECB
	V加密结果方法      string //支持base64 hex
}

func (*N新ase) AesDecryptCBC

func (a *N新ase) AesDecryptCBC(encrypted []byte) (decrypted []byte, err error)

func (*N新ase) AesDecryptCFB

func (a *N新ase) AesDecryptCFB(encrypted []byte) (decrypted []byte, err error)

func (*N新ase) AesDecryptECB

func (a *N新ase) AesDecryptECB(encrypted []byte) (decrypted []byte, err error)

func (*N新ase) AesEncryptCBC

func (a *N新ase) AesEncryptCBC(origData []byte) (encrypted []byte, err error)

=================== CBC ======================

func (*N新ase) AesEncryptCFB

func (a *N新ase) AesEncryptCFB(origData []byte) (encrypted []byte, err error)

=================== CFB ======================

func (*N新ase) AesEncryptECB

func (a *N新ase) AesEncryptECB(origData []byte) (encrypted []byte, err error)

=================== ECB ======================

func (*N新ase) F加密信息

func (a *N新ase) F加密信息(body string) (string, error)

func (*N新ase) F获取偏移量

func (a *N新ase) F获取偏移量() (iv []byte)

func (*N新ase) F获取加密补全方法

func (a *N新ase) F获取加密补全方法() func(ciphertext []byte, blockSize int) []byte

func (*N新ase) F获取解密补全方法

func (a *N新ase) F获取解密补全方法() func(origData []byte) []byte

func (*N新ase) F解密信息

func (a *N新ase) F解密信息(body string) (string, error)

type S3Desc加解密

type S3Desc加解密 struct {
	//V密钥       []byte
	V加密块      cipher.Block
	V是否base64 bool
}

func F新建3Desc加解密

func F新建3Desc加解密(key ...string) (加解密 *S3Desc加解密, err error)

这个每次加密数值都是一样的。

func (*S3Desc加解密) F加密信息

func (a *S3Desc加解密) F加密信息(body string) (string, error)

func (*S3Desc加解密) F加密字节

func (a *S3Desc加解密) F加密字节(body []byte) (string, error)

func (*S3Desc加解密) F解密信息

func (a *S3Desc加解密) F解密信息(body string) (string, error)

type SASE加解密

type SASE加解密 struct {
	V密钥 []byte
}

func (*SASE加解密) F加密信息

func (a *SASE加解密) F加密信息(body string) (string, error)

func (*SASE加解密) F解密信息

func (a *SASE加解密) F解密信息(body string) (string, error)

type S加解密接口

type S加解密接口 interface {
	F加密信息(body string) (string, error)
	F解密信息(body string) (string, error)
}

func F新建Ase加解密

func F新建Ase加解密(key ...string) S加解密接口

每次加密的结果都不一样。

func F新建Ase配置

func F新建Ase配置(args ...string) S加解密接口

func F新建ase

func F新建ase(opts ...I设置接口) S加解密接口

Jump to

Keyboard shortcuts

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