Из документации по операции KMS GenerateDataKey
https://docs.aws.amazon.com/kms/latest/APIReference/API_GenerateDataKey.html
We recommend that you use the following pattern to encrypt data locally in your application:
Use the GenerateDataKey operation to get a data encryption key.
Use the plaintext data key (returned in the Plaintext field of the response) to encrypt data locally, then erase the plaintext data key from memory.
Будет ли этого кода достаточно, чтобы убедиться, что ключ открытого текста был стерт из памяти при его использовании.
const aws = require("aws-sdk");
const kms = new aws.KMS({...config});
(async () => {
/** {Plaintext: Buffer, CiphertextBlob: Buffer} **/
let dataKey = await kms.generateDataKey({...options}).promise();
let encryptedString = MyEncryptionFunction(dataKey.Plaintext, "Hello World");
dataKey.Plaintext.fill(0); //overwrite the buffer with zeroes to erase from memory;
})();
function MyEncryptionFunction(key, dataString) {
let iv = crypto.randomBytes(16);
let cipher = crypto.createCipheriv("aes256", key, iv);
return cipher.update(dataString, "utf8", "hex") + cipher.final("hex");
}
Безопасно ли предположить, что aws sdk не пропускает/не копирует ключ в другие части памяти, и то же самое с функцией createCipheriv
встроенной криптобиблиотеки, и поэтому простая перезапись буфера Plaintext
нулями должна достаточно стереть ключ из Память?