This is a simple example of an HTTP server in Go that implements AES encryption using CFB (Cipher Feedback) mode.
The server has two routes:
/encrypt/{key}/{plainText}
- Receives a key and plain text as parameters and returns the encrypted text in hexadecimal format./decrypt/{key}/{cipherText}
- Receives a key and a hexadecimal encrypted text as parameters and returns the original plain text.
Make sure you have Go installed on your machine before running this code.
-
Clone this repository to your local environment.
-
Navigate to the project directory using the terminal.
-
Run the following command to start the server:
go run main.go
-
The server will run at http://localhost:3000 or at the port defined by the PORT environment variable.
-
Use an HTTP client (such as cURL or Postman) to send requests to the /encrypt and /decrypt routes as needed.
Encrypt Text
Send a GET request to http://localhost:3000/encrypt/mykey/HelloWorld
:
curl http://localhost:3000/encrypt/mykey/HelloWorld
Response:
5f0e0a33c22786762fbde72e1c78e900
Decrypt Text
Send a GET request to http://localhost:3000/decrypt/mykey/5f0e0a33c22786762fbde72e1c78e900
:
curl http://localhost:3000/decrypt/mykey/5f0e0a33c22786762fbde72e1c78e900
Response:
HelloWorld
- Make sure to keep the encryption and decryption keys consistent when using the server.
- This is just a simple example for educational purposes and should not be used in production without considering additional security aspects.