protected ContentCryptoMaterial createContentMaterialFromMetadata()

in oss-20190517/src/main/java/com/aliyun/sdk/service/oss20190517/encryption/internal/CryptoModuleBase.java [296:328]


    protected ContentCryptoMaterial createContentMaterialFromMetadata(Map<String, String> headers) {
        // Encrypted CEK and encrypted IV.
        String b64CEK = headers.get(CryptoHeaders.X_OSS_META_CRYPTO_KEY);
        String b64IV = headers.get(CryptoHeaders.X_OSS_META_CRYPTO_IV);
        if (b64CEK == null || b64IV == null) {
            throw new OSSClientException("Content encrypted key  or encrypted iv not found.", null);
        }
        byte[] encryptedCEK = Base64Util.decodeString(b64CEK);
        byte[] encryptedIV = Base64Util.decodeString(b64IV);

        // Key wrap algorithm
        final String keyWrapAlgo = headers.get(CryptoHeaders.X_OSS_META_CRYPTO_WRAP_ALG);
        if (keyWrapAlgo == null)
            throw new OSSClientException("Key wrap algorithm should not be null.", null);

        // CEK algorithm
        String cekAlgo = headers.get(CryptoHeaders.X_OSS_META_CRYPTO_CEK_ALG);

        // Description
        String mateDescString = headers.get(CryptoHeaders.X_OSS_META_CRYPTO_MATDESC);
        Map<String, String> matDesc = Utils.getDescFromJsonString(mateDescString);

        // Decrypt the secured CEK to CEK.
        ContentCryptoMaterial contentMaterial = new ContentCryptoMaterial();
        contentMaterial.setEncryptedCEK(encryptedCEK);
        contentMaterial.setEncryptedIV(encryptedIV);
        contentMaterial.setMaterialsDescription(matDesc);
        contentMaterial.setContentCryptoAlgorithm(cekAlgo);
        contentMaterial.setKeyWrapAlgorithm(keyWrapAlgo);
        encryptionMaterials.decryptCEK(contentMaterial);

        return contentMaterial;
    }