diff --git a/encryption/encryption.go b/encryption/encryption.go index 12eb442f37ba6b6a214e682e2c3ffac013ffa0a1..909d48cc9936341be6191e7165422cc25ae7a029 100644 --- a/encryption/encryption.go +++ b/encryption/encryption.go @@ -45,22 +45,23 @@ func Encrypt(plaintext string, key string) (string, error) { return string(gcm.Seal(nonce, nonce, []byte(plaintext), nil)), nil } -func Decrypt(ciphertext string, key string) ([]byte, error) { +func Decrypt(ciphertext string, key string) (string, error) { c, err := aes.NewCipher([]byte(key)) if err != nil { - return nil, err + return "", err } gcm, err := cipher.NewGCM(c) if err != nil { - return nil, err + return "", err } nonceSize := gcm.NonceSize() if len(ciphertext) < nonceSize { - return nil, errors.New("ciphertext too short") + return "", errors.New("ciphertext too short") } nonce, ciphertext := ciphertext[:nonceSize], ciphertext[nonceSize:] - return gcm.Open(nil, []byte(nonce), []byte(ciphertext), nil) + value, err := gcm.Open(nil, []byte(nonce), []byte(ciphertext), nil) + return string(value), err }