This is a sample code to demo how to implement S3 SSE-C in Go.
To install this package, you need to install Go and set your Go workspace first.
$ go get -u github.com/anrylu/s3-sse-c-sample$ cd s3-sse-c-sample
$ go get -u github.com/golang/dep/cmd/dep
$ dep ensureTo execute this project, you need to have access & secret key to access S3. Or you can setup an instance with IAM role permission.
$ export S3_SSE_C_SAMPLE_REGION="us-east-1"
$ export S3_SSE_C_SAMPLE_BUCKET_NAME="s3-sse-c-sample"$ export S3_SSE_C_SAMPLE_ACCESS_KEY=<YOU_ACCESS_KEY>
$ export S3_SSE_C_SAMPLE_SECRET_KEY=<YOU_SECRET_KEY>$ openssl rand -out PlaintextKeyMaterial.bin 32
$ cat PlaintextKeyMaterial.bin | base64$ cat PlaintextKeyMaterial.bin | openssl dgst -md5 -binary | base64$ export S3_SSE_C_SAMPLE_SSE_CUSTOMER_KEY_BASE64=<YOU_ENCRYPTION_KEY_IN_BASE64>
$ export S3_SSE_C_SAMPLE_SSE_CUSTOMER_KEY_MD5_BASE64=<YOU_ENCRYPTION_KEY_MD5_IN_BASE64>$ go run cmd/server/main.goTo test, you need to have curl installed.
curl -vvv -X POST http://localhost:8080/upload -F "file=@./test.jpg" -H "Content-Type: multipart/form-data"Just check if the file is successfully uploaded to S3 and see if it has "Server-side encryption".
curl -vvv http://localhost:8080/download/test.jpg -o test-download.jpgJust check if test.jpg & test-download.jpg are the same.