init repo

This commit is contained in:
2024-09-14 22:39:50 +08:00
commit e8314a95bf
14 changed files with 785 additions and 0 deletions

31
utils/encrypt.go Normal file
View File

@@ -0,0 +1,31 @@
package utils
import (
"crypto/aes"
)
func AesEcbDecrypt(key []byte, src []byte) ([]byte, error) {
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
dst := make([]byte, 0, len(src))
tmp := make([]byte, aes.BlockSize)
for i := 0; i < len(src); i += aes.BlockSize {
block.Decrypt(tmp, src[i:i+aes.BlockSize])
if i == len(src)-aes.BlockSize {
pad := int(tmp[len(tmp)-1])
if pad > aes.BlockSize {
pad = 0
}
dst = append(dst, tmp[:aes.BlockSize-pad]...)
} else {
dst = append(dst, tmp...)
}
}
return dst, nil
}

11
utils/file.go Normal file
View File

@@ -0,0 +1,11 @@
package utils
import (
"path/filepath"
"strings"
)
func ReplaceExtension(filepathStr, newExt string) string {
ext := filepath.Ext(filepathStr)
return strings.TrimSuffix(filepathStr, ext) + newExt
}