in oss-20190517/src/main/java/com/aliyun/sdk/service/oss20190517/encryption/SimpleRSAEncryptionMaterials.java [212:242]
public void decryptCEK(ContentCryptoMaterial contentMaterial) {
assertParameterNotNull(contentMaterial, "ContentCryptoMaterialRW");
assertParameterNotNull(contentMaterial.getEncryptedCEK(), "ContentCryptoMaterialRW#getEncryptedCEK");
assertParameterNotNull(contentMaterial.getEncryptedIV(), "ContentCryptoMaterialRW#getEncryptedIV");
assertParameterNotNull(contentMaterial.getKeyWrapAlgorithm(), "ContentCryptoMaterialRW#getKeyWrapAlgorithm");
if (!contentMaterial.getKeyWrapAlgorithm().equalsIgnoreCase(KEY_WRAP_ALGORITHM)) {
throw new OSSClientException(
"Unrecognize your object key wrap algorithm: " + contentMaterial.getKeyWrapAlgorithm(), null);
}
try {
KeyPair keyPair = findKeyPairByDescription(contentMaterial.getMaterialsDescription());
if (keyPair == null) {
Map.Entry<KeyPair, Map<String, String>> entry = getTailByReflection(keyPairDescMaterials);
keyPair = entry.getKey();
}
Key key = keyPair.getPrivate();
Cipher cipher = Cipher.getInstance(KEY_WRAP_ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] cekBytes = cipher.doFinal(contentMaterial.getEncryptedCEK());
byte[] iv = cipher.doFinal(contentMaterial.getEncryptedIV());
SecretKey cek = new SecretKeySpec(cekBytes, "");
contentMaterial.setCEK(cek);
contentMaterial.setIV(iv);
} catch (Exception e) {
throw new OSSClientException("Unable to decrypt the secured content key and iv. " + e.getMessage(), e);
}
}