mirror of
https://github.com/skyle1995/NetworkAuth.git
synced 2026-05-25 02:24:05 +08:00
Add classification annotations
This commit is contained in:
@@ -8,12 +8,20 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ============================================================================
|
||||
// 结构体定义
|
||||
// ============================================================================
|
||||
|
||||
// EasyEncrypt 易加密算法结构体
|
||||
type EasyEncrypt struct {
|
||||
encryptKey []int // 加密密钥
|
||||
decryptKey []int // 解密密钥
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 构造函数
|
||||
// ============================================================================
|
||||
|
||||
// NewEasyEncrypt 创建新的易加密实例
|
||||
func NewEasyEncrypt(encryptKey, decryptKey []int) *EasyEncrypt {
|
||||
return &EasyEncrypt{
|
||||
@@ -22,17 +30,21 @@ func NewEasyEncrypt(encryptKey, decryptKey []int) *EasyEncrypt {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 密钥生成函数
|
||||
// ============================================================================
|
||||
|
||||
// GenerateEasyKey 生成易加密密钥对
|
||||
func GenerateEasyKey() ([]int, []int, error) {
|
||||
// 使用crypto/rand生成随机长度(15-30位)
|
||||
var lengthByte [1]byte
|
||||
|
||||
|
||||
// 生成加密密钥长度
|
||||
if _, err := rand.Read(lengthByte[:]); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
encryptKeyLen := 15 + int(lengthByte[0])%16 // 15-30位随机长度
|
||||
|
||||
|
||||
encryptKey := make([]int, encryptKeyLen)
|
||||
encryptBytes := make([]byte, encryptKeyLen)
|
||||
if _, err := rand.Read(encryptBytes); err != nil {
|
||||
@@ -47,7 +59,7 @@ func GenerateEasyKey() ([]int, []int, error) {
|
||||
return nil, nil, err
|
||||
}
|
||||
decryptKeyLen := 15 + int(lengthByte[0])%16 // 15-30位随机长度
|
||||
|
||||
|
||||
decryptKey := make([]int, decryptKeyLen)
|
||||
decryptBytes := make([]byte, decryptKeyLen)
|
||||
if _, err := rand.Read(decryptBytes); err != nil {
|
||||
@@ -60,6 +72,10 @@ func GenerateEasyKey() ([]int, []int, error) {
|
||||
return encryptKey, decryptKey, nil
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 方法函数
|
||||
// ============================================================================
|
||||
|
||||
// Encrypt 加密函数 - 对应 UserLogin_encrypt_Up_42510
|
||||
func (e *EasyEncrypt) Encrypt(input string) string {
|
||||
if input == "" {
|
||||
@@ -140,6 +156,10 @@ func (e *EasyEncrypt) Decrypt(input string) string {
|
||||
return result.String()
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 工具函数
|
||||
// ============================================================================
|
||||
|
||||
// EncryptWithKey 使用指定密钥加密
|
||||
func EncryptWithKey(input string, key []int) string {
|
||||
if input == "" || len(key) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user