mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-12-08 08:00:26 +08:00
IP库加密/其他对IP库的改进
This commit is contained in:
32
pkg/iplibrary/encrypt.go
Normal file
32
pkg/iplibrary/encrypt.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package iplibrary
|
||||
|
||||
import "github.com/TeaOSLab/EdgeCommon/pkg/nodeutils"
|
||||
|
||||
type Encrypt struct {
|
||||
}
|
||||
|
||||
func NewEncrypt() *Encrypt {
|
||||
return &Encrypt{}
|
||||
}
|
||||
|
||||
func (this *Encrypt) Encode(srcData []byte, password string) ([]byte, error) {
|
||||
var method = nodeutils.AES256CFBMethod{}
|
||||
err := method.Init([]byte(password), []byte(password))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return method.Encrypt(srcData)
|
||||
}
|
||||
|
||||
func (this *Encrypt) Decode(encodedData []byte, password string) ([]byte, error) {
|
||||
var method = nodeutils.AES256CFBMethod{}
|
||||
err := method.Init([]byte(password), []byte(password))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return method.Decrypt(encodedData)
|
||||
}
|
||||
Reference in New Issue
Block a user