Added web service

This commit is contained in:
2024-11-17 09:19:31 -05:00
parent a773b38794
commit 4803855e61
6 changed files with 167 additions and 47 deletions

View File

@@ -5,6 +5,7 @@ import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/base64"
"io"
)
@@ -14,6 +15,26 @@ func pkcs7pad(data []byte, blockSize int) []byte {
return append(data, padding...)
}
func (g *Generator) Decrypt(s string) (string, error) {
c, err := aes.NewCipher(g.config.encryptionKeyBin)
if err != nil {
return "", err
}
decoded, err := base64.RawURLEncoding.DecodeString(s)
if err != nil {
return "", err
}
iv := decoded[:aes.BlockSize]
cryptText := decoded[aes.BlockSize:]
cbc := cipher.NewCBCDecrypter(c, iv)
cbc.CryptBlocks(cryptText, cryptText)
return string(cryptText), err
}
func (g *Generator) generateBaseAesEncUrl(file []byte) (string, error) {
c, err := aes.NewCipher(g.config.encryptionKeyBin)
if err != nil {