/** * Evaluate whether an EncryptedKey's CarriedKeyName matches one of the KeyName values * from the EncryptedData context. * * @param encryptedData the EncryptedData context * @param encryptedKey the candidate Encryptedkey to evaluate * @return true if the encrypted key's carried key name matches that of the encrytped data, * false otherwise */ protected boolean matchCarriedKeyName(EncryptedData encryptedData, EncryptedKey encryptedKey) { if (encryptedKey.getCarriedKeyName() == null || DatatypeHelper.isEmpty(encryptedKey.getCarriedKeyName().getValue()) ) { return true; } if (encryptedData.getKeyInfo() == null || encryptedData.getKeyInfo().getKeyNames().isEmpty() ) { return false; } String keyCarriedKeyName = encryptedKey.getCarriedKeyName().getValue(); List<String> dataKeyNames = KeyInfoHelper.getKeyNames(encryptedData.getKeyInfo()); return dataKeyNames.contains(keyCarriedKeyName); }
/** * Evaluate whether an EncryptedKey's CarriedKeyName matches one of the KeyName values * from the EncryptedData context. * * @param encryptedData the EncryptedData context * @param encryptedKey the candidate Encryptedkey to evaluate * @return true if the encrypted key's carried key name matches that of the encrytped data, * false otherwise */ protected boolean matchCarriedKeyName(EncryptedData encryptedData, EncryptedKey encryptedKey) { if (encryptedKey.getCarriedKeyName() == null || DatatypeHelper.isEmpty(encryptedKey.getCarriedKeyName().getValue()) ) { return true; } if (encryptedData.getKeyInfo() == null || encryptedData.getKeyInfo().getKeyNames().isEmpty() ) { return false; } String keyCarriedKeyName = encryptedKey.getCarriedKeyName().getValue(); List<String> dataKeyNames = KeyInfoHelper.getKeyNames(encryptedData.getKeyInfo()); return dataKeyNames.contains(keyCarriedKeyName); }
if (encKey.getCarriedKeyName() == null) { encKey.setCarriedKeyName(carriedKeyNameBuilder.buildObject()); encKey.getCarriedKeyName().setValue(carriedKeyNameValue);