Updated
Some checks failed
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Has been cancelled

This commit is contained in:
2025-05-22 20:15:01 -04:00
parent e9e0d30c7a
commit b0d4f3f890
2 changed files with 25 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ import (
"crypto/cipher"
"crypto/rand"
"encoding/base64"
"errors"
"io"
)
@@ -15,6 +16,23 @@ func pkcs7pad(data []byte, blockSize int) []byte {
return append(data, padding...)
}
func pkcs7unpad(data []byte) ([]byte, error) {
length := len(data)
if length == 0 {
return nil, errors.New("invalid padding size")
}
padLen := int(data[length-1])
if padLen > length || padLen == 0 {
return nil, errors.New("invalid padding")
}
for _, v := range data[length-padLen:] {
if int(v) != padLen {
return nil, errors.New("invalid padding")
}
}
return data[:length-padLen], nil
}
func (g *Generator) Decrypt(s string) (string, error) {
c, err := aes.NewCipher(g.encryptionKey)
if err != nil {
@@ -32,7 +50,12 @@ func (g *Generator) Decrypt(s string) (string, error) {
cbc.CryptBlocks(cryptText, cryptText)
return string(cryptText), err
decrypted, err := pkcs7unpad(cryptText)
if err != nil {
return "", err
}
return string(decrypted), err
}
func (g *Generator) generateBaseAesEncUrl(file []byte) (string, error) {