TODO: maybe move encryption/decryption into helper? AES + Base64 encryption using ENCRYPTION_SECRET in .env as key
(encryptionSecret, plainText string)
| 34 | // TODO: maybe move encryption/decryption into helper? |
| 35 | // AES + Base64 encryption using ENCRYPTION_SECRET in .env as key |
| 36 | func Encrypt(encryptionSecret, plainText string) (string, errors.Error) { |
| 37 | // add suffix to the data part |
| 38 | inputBytes := append([]byte(plainText), 123, 110, 100, 100, 116, 102, 125) |
| 39 | // perform encryption |
| 40 | output, err := AesEncrypt(inputBytes, []byte(encryptionSecret)) |
| 41 | if err != nil { |
| 42 | return plainText, err |
| 43 | } |
| 44 | // Return the result after Base64 processing |
| 45 | return base64.StdEncoding.EncodeToString(output), nil |
| 46 | } |
| 47 | |
| 48 | // Base64 + AES decryption using ENCRYPTION_SECRET in .env as key |
| 49 | func Decrypt(encryptionSecret, encryptedText string) (string, errors.Error) { |