如果您使用AWS SDK进行API请求,则它将自动使用AWS SigVer4进行签名。在使用AWS KMS管理密钥的服务器端加密时,请确保使用服务器端加密的AWS SDK版本支持AWS SigVer4。以下是JavaScript中使用AWS SDK进行服务器端加密的示例代码:
const AWS = require('aws-sdk'); const kms = new AWS.KMS({region: 'us-east-1'});
const plaintext = 'my secret data';
const params = {
KeyId: 'alias/example', // alias of the CMK to use for encrypting a file
Plaintext: plaintext,
};
kms.encrypt(params, (err, data) => {
if (err) console.log(err);
else console.log(Encrypted plaintext: ${data.CiphertextBlob.toString('base64')}
);
});
请注意,此代码仅适用于Node.js运行时。如果您使用其他语言的AWS SDK,则可以参考AWS文档以了解如何进行AWS SigVer4签名。