AWS KMS可以与其他云服务进行互操作,例如将加密密钥存储在AWS KMS中,然后使用该密钥来加密和解密数据,同时可以将加密的数据存储在其他云服务中进行存储和处理。
以下是使用AWS KMS和Amazon S3相互操作的示例代码:
import boto3
kms = boto3.client('kms')
result = kms.create_key(Description='My customer master key')
print(result['KeyMetadata']['KeyId'])
import boto3
kms = boto3.client('kms')
response = kms.encrypt( KeyId='alias/MyKey', Plaintext=b'Hello World', )
print(response['CiphertextBlob'])
import boto3
kms = boto3.client('kms')
response = kms.decrypt( CiphertextBlob=b'bytes', )
print(response['Plaintext'])
import boto3
s3 = boto3.client('s3')
with open("test.txt", "rb") as f: s3.upload_fileobj(f, "mybucket", "test.txt")
print("https://s3.amazonaws.com/mybucket/test.txt")
import boto3
s3 = boto3.client('s3')
with open("test.txt", "wb") as f: s3.download_fileobj("mybucket", "test.txt", f)
kms = boto3.client('kms')
with open("test.txt", "rb") as f: data = f.read() response = kms.decrypt( CiphertextBlob=data )
print(response['Plaintext'])