Skip to content

Instantly share code, notes, and snippets.

@jhcaiced
Created January 30, 2018 10:24
Show Gist options
  • Save jhcaiced/a2471292cb4511d1dbb764b70c6648bd to your computer and use it in GitHub Desktop.
Save jhcaiced/a2471292cb4511d1dbb764b70c6648bd to your computer and use it in GitHub Desktop.
AWS S3 Encryption with User Keys
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