Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中使用AWS KMS以编程方式解密cypherTextBlob?InvalidCiphertextException_Java_Amazon Web Services_Encryption_Base64_Aws Kms - Fatal编程技术网

在Java中使用AWS KMS以编程方式解密cypherTextBlob?InvalidCiphertextException

在Java中使用AWS KMS以编程方式解密cypherTextBlob?InvalidCiphertextException,java,amazon-web-services,encryption,base64,aws-kms,Java,Amazon Web Services,Encryption,Base64,Aws Kms,我对密码学有点陌生,以前从未使用AWS KMS加密数据。 我正在使用AWS SDK for Java for KMS。 但是,在尝试使用AWS KMS API操作进行加密和解密时,我遇到了异常InvalidCiphertextException <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>kms</artifactId>

我对密码学有点陌生,以前从未使用AWS KMS加密数据。 我正在使用AWS SDK for Java for KMS。 但是,在尝试使用AWS KMS API操作进行加密和解密时,我遇到了异常InvalidCiphertextException

<dependency>
      <groupId>software.amazon.awssdk</groupId>
      <artifactId>kms</artifactId>
      <version>2.15.19</version>
  </dependency>
解密方法中的解密部分

public String decrypt(String cipherText){
ByteBuffer cyphertextBlob = ByteBuffer.wrap(cipherText.getBytes());

//Point 1: Exception is thrown at this point while calling decrypt operation API.

DecryptRequest request = new DecryptRequest().withKeyId(keyId).withCiphertextBlob(cyphertextBlob);
}
问题是我在进行api调用时(第1点)出现以下错误

com.amazonaws.services.kms.model.InvalidCiphertextException:null(服务:AWSKMS;状态代码:400;错误代码:InvalidCiphertextException;请求ID:45720b33-3637-490a-8c6a-d7491ccadf94;代理:null)

InvalidCiphertextException。在浏览AWS文件时,以下是我理解的要点

  • 加密上下文以加密方式绑定到cypher文本,因此如果我们在解密操作中不提供encryptionContext,则会抛出InvalidCiphertextException。但我在加密时不提供encryptionContext
  • 在准备加密和解密上下文时,我还尝试使用withEncryptionContext(null)
在使用解密请求之前,我是否需要执行任何其他步骤来操作/转换密码文本


有人能帮忙吗?

请在这里更新,以防有人在这个问题上有库存

调试时发现,使用KMS响应的get方法获得的ByteBuffer对象的容量和限制与使用decrypt方法中的密文创建时的默认容量和限制不同。因此,这导致了异常

public String decrypt(String cipherText){
ByteBuffer cyphertextBlob = ByteBuffer.wrap(cipherText.getBytes());

//Point 1: Exception is thrown at this point while calling decrypt operation API.

DecryptRequest request = new DecryptRequest().withKeyId(keyId).withCiphertextBlob(cyphertextBlob);
}