无法解密由AWS CloudFront加密的字符串

时间:2018-06-21 11:15:06

标签: encryption amazon-cloudfront

我使用公共密钥通过Cloudfront配置配置文件加密了数据。当我尝试通过将私钥的.pem文件放在本地进行解密时,会出现空指针异常。

下面是正在使用的代码片段和堆栈跟踪。我们非常感谢您的帮助。

    // 1. Base 64 decoded the string
    // set up the keys and requored params
    final AwsCrypto crypto = new AwsCrypto();
    // 2. Instantiate a JCE master key
    final JceMasterKey masterKey = JceMasterKey.getInstance(
                    publicKey,
                    privateKey,
                    PROVIDER_NAME,
                    KEY_NAME,
                    ALGORITHM);

    // 3. Decrypt the data 
    final CryptoResult <byte[], ? > result = crypto.decryptData(masterKey, bytesToDecrypt);
    return new String(result.getResult());


Stack trace : 
Exception in thread "main" java.lang.NullPointerException
    at java.util.ArrayList.<init>(ArrayList.java:178)
    at com.amazonaws.encryptionsdk.model.CiphertextHeaders.getEncryptedKeyBlobs(CiphertextHeaders.java:773)
    at com.amazonaws.encryptionsdk.internal.DecryptionHandler.getDataKey(DecryptionHandler.java:331)
    at com.amazonaws.encryptionsdk.internal.DecryptionHandler.readHeaderFields(DecryptionHandler.java:382)
    at com.amazonaws.encryptionsdk.internal.DecryptionHandler.<init>(DecryptionHandler.java:124)
    at com.amazonaws.encryptionsdk.AwsCrypto.decryptData(AwsCrypto.java:242)
    at com.amazonaws.encryptionsdk.AwsCrypto.decryptData(AwsCrypto.java:233)

谢谢。

0 个答案:

没有答案