Created
January 30, 2018 10:24
-
-
Save jhcaiced/a2471292cb4511d1dbb764b70c6648bd to your computer and use it in GitHub Desktop.
AWS S3 Encryption with User Keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function addEncryptionHeaders(encryptionKey) { | |
| return function(req) { | |
| const key = Buffer.alloc(32).fill(encryptionKey) | |
| const key64 = AWS.util.base64.encode(key) | |
| const keyMD5 = AWS.util.crypto.md5(key.toString(), 'base64') | |
| req.httpRequest.headers['x-amz-server-side-encryption-customer-algorithm'] = 'AES256' | |
| req.httpRequest.headers['x-amz-server-side-encryption-customer-key'] = key64 | |
| req.httpRequest.headers['x-amz-server-side-encryption-customer-key-MD5'] = keyMD5 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment