[英]how to resolve Exception in thread “main” com.amazonaws.AmazonClientException: Unable to build cipher: Illegal key size using aws s3
I am trying for encryption and decryption using amazon aws. 我正在尝试使用amazon aws进行加密和解密。 I got exception like
我有例外
Exception in thread "main" com.amazonaws.AmazonClientException: Unable to build cipher: Illegal key size
Make sure you have the JCE unlimited strength policy files installed and configured for your JVM
at com.amazonaws.services.s3.internal.crypto.ContentCryptoScheme.createCipherLite(ContentCryptoScheme.java:190)
at com.amazonaws.services.s3.internal.crypto.ContentCryptoMaterial.wrap(ContentCryptoMaterial.java:823)
at com.amazonaws.services.s3.internal.crypto.S3CryptoModuleBase.buildContentCryptoMaterial(S3CryptoModuleBase.java:535)
at com.amazonaws.services.s3.internal.crypto.S3CryptoModuleBase.newContentCryptoMaterial(S3CryptoModuleBase.java:483)
at com.amazonaws.services.s3.internal.crypto.S3CryptoModuleBase.createContentCryptoMaterial(S3CryptoModuleBase.java:449)
at com.amazonaws.services.s3.internal.crypto.S3CryptoModuleBase.putObjectUsingMetadata(S3CryptoModuleBase.java:165)
at com.amazonaws.services.s3.internal.crypto.S3CryptoModuleBase.putObjectSecurely(S3CryptoModuleBase.java:159)
at com.amazonaws.services.s3.internal.crypto.CryptoModuleDispatcher.putObjectSecurely(CryptoModuleDispatcher.java:107)
at com.amazonaws.services.s3.AmazonS3EncryptionClient.putObject(AmazonS3EncryptionClient.java:485)
at testKMSkeyUploadObject.main(testKMSkeyUploadObject.java:91)
Caused by: java.security.InvalidKeyException: Illegal key size
at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1039)
at javax.crypto.Cipher.implInit(Cipher.java:805)
at javax.crypto.Cipher.chooseProvider(Cipher.java:864)
at javax.crypto.Cipher.init(Cipher.java:1396)
at javax.crypto.Cipher.init(Cipher.java:1327)
at com.amazonaws.services.s3.internal.crypto.ContentCryptoScheme.createCipherLite(ContentCryptoScheme.java:187)
... 9 more
please help me.
when I was trying to put object for doing encryption using AmazonS3EncryptionClient I am getting exception. 当我试图将对象用于使用AmazonS3EncryptionClient进行加密时,我得到了异常。 How to resolve this error.
如何解决此错误。
AmazonS3EncryptionClient s3 = new AmazonS3EncryptionClient(credentials,materialProvider);
PutObjectRequest putRequest = new PutObjectRequest(
bucket, kms_cmk_id, new ByteArrayInputStream(plaintext), metadata);
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
putRequest.setMetadata(objectMetadata);
System.out.println(putRequest.getKey());
s3.putObject(putRequest); //getting exception here
It seems the problem is with key size and IMO Amazon has hard coded it somewhere in their code. 似乎问题在于密钥大小和IMO亚马逊在其代码中的某处硬编码。 The solution may be to go for unlimited strength file which you can download from:
解决方案可能是获取无限强度文件,您可以从以下位置下载:
Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files 6 Java密码术扩展(JCE)无限强度管辖政策文件6
Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files 7 Download Java密码术扩展(JCE)无限强度管辖权政策文件7下载
Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files 8 Download Java密码术扩展(JCE)无限强度管辖权政策文件8下载
Install the file in ${java.home}/jre/lib/security/
. 在
${java.home}/jre/lib/security/
安装该文件。
I resolved this problem by creating encryption key in IAM Management Console. 我通过在IAM管理控制台中创建加密密钥来解决此问题。 I used that encryption key when I was encrypting.
我在加密时使用了加密密钥。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.