public DataKey decryptDataKey()

in src/main/java/com/amazonaws/encryptionsdk/jce/JceMasterKey.java [154:182]


  public DataKey<JceMasterKey> decryptDataKey(
      final CryptoAlgorithm algorithm,
      final Collection<? extends EncryptedDataKey> encryptedDataKeys,
      final Map<String, String> encryptionContext)
      throws UnsupportedProviderException, AwsCryptoException {
    final List<Exception> exceptions = new ArrayList<>();
    // Find an encrypted key who's provider and info match us
    for (final EncryptedDataKey edk : encryptedDataKeys) {
      try {
        if (edk.getProviderId().equals(getProviderId())
            && Utils.arrayPrefixEquals(
                edk.getProviderInformation(), keyIdBytes_, keyIdBytes_.length)) {
          final byte[] decryptedKey = jceKeyCipher_.decryptKey(edk, keyId_, encryptionContext);

          // Validate that the decrypted key length is as expected
          if (decryptedKey.length == algorithm.getDataKeyLength()) {
            return new DataKey<>(
                new SecretKeySpec(decryptedKey, algorithm.getDataKeyAlgo()),
                edk.getEncryptedDataKey(),
                edk.getProviderInformation(),
                this);
          }
        }
      } catch (final Exception ex) {
        exceptions.add(ex);
      }
    }
    throw buildCannotDecryptDksException(exceptions);
  }