You've already forked img-proxy-url-generator
Added web service
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user