Skip to content

Instantly share code, notes, and snippets.

View jhcaiced's full-sized avatar

Jhon H. Caicedo jhcaiced

View GitHub Profile
@jhcaiced
jhcaiced / gist:a2471292cb4511d1dbb764b70c6648bd
Created January 30, 2018 10:24
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
}
}