简体   繁体   English

我可以将AWS KMS加密用于Android中的客户端加密吗?

[英]Can I use AWS KMS encryption for client side encryption in Android?

There is no method for KMS encryption in Android AWS SDK. Android AWS SDK中没有用于KMS加密的方法。 On the server side we use KMSEncryptionMaterialsProvider to create AmazonS3EncryptionClient object, but this class is not available in Android SDK. 在服务器端,我们使用KMSEncryptionMaterialsProvider创建AmazonS3EncryptionClient对象,但是此类在Android SDK中不可用。 I tried using the Java SDK in my Android project but it threw an exception 我尝试在Android项目中使用Java SDK,但发生了异常

Code: 码:

KMSEncryptionMaterialsProvider materialProvider = new KMSEncryptionMaterialsProvider(kms_cmk_id);
encryptionClient = new AmazonS3EncryptionClient(new ProfileCredentialsProvider(), materialProvider,
                new CryptoConfiguration())
            .withRegion(Region.getRegion(Regions.US_WEST_2));

Exception 例外

Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.management.MBeanServerFactory" on path: DexPathList 原因:java.lang.ClassNotFoundException:在路径:DexPathList上找不到类“ javax.management.MBeanServerFactory”

Yes, it is possible. 对的,这是可能的。 I'll give you three options, but all of them require getting your hands a little dirtier. 我给您三个选择,但是所有这些都需要使您的手更脏一点。

Option 1: You can derive your own implementation of a KMS Encryption Materials Provider. 选项1:您可以派生自己的KMS加密材料提供程序实现。 Even though that specific class (and likely some of its dependencies) are not present in the AWS Android SDK, you have the interface you need on the SDK: EncryptionMaterialsProvider . 即使该特定类(以及可能的某些依赖项)在AWS Android SDK中不存在,您仍可以在SDK上使用所需的接口: EncryptionMaterialsProvider It should be possible to implement your own provider based on that. 可以基于此实现自己的提供程序。

Option 2: Use the KMS Client provided in the Android SDK to retrieve your own encryption materials from KMS and then pass a StaticEncryptionMaterialsProvider to the S3 client. 选项2:使用Android SDK中提供的KMS客户端从KMS检索您自己的加密材料,然后将StaticEncryptionMaterialsProvider传递给S3客户端。

Option 3: Deal with encryption/decryption yourself. 选项3:自己处理加密/解密。 It's technically possible for you to retrieve the encryption materials using the KMS client, and then follow the KMS guidance on the official documentation to encrypt/decrypt your data. 从技术上讲,您可以使用KMS客户端检索加密材料,然后按照官方文档上的KMS指南对数据进行加密/解密。 Please just do this if you are comfortable with cryptography. 如果您对密码学感到满意,请这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM