public ByteBuf decrypt(MessageMetadata msgMetadata, ByteBuf payload, CryptoKeyReader keyReader) { // If dataKey is present, attempt to decrypt using the existing key if (dataKey != null) { ByteBuf decryptedData = getKeyAndDecryptData(msgMetadata, payload); // If decryption succeeded, data is non null if (decryptedData != null) { return decryptedData; } } // dataKey is null or decryption failed. Attempt to regenerate data key List<EncryptionKeys> encKeys = msgMetadata.getEncryptionKeysList(); EncryptionKeys encKeyInfo = encKeys.stream().filter(kbv -> { byte[] encDataKey = kbv.getValue().toByteArray(); List<KeyValue> encKeyMeta = kbv.getMetadataList(); return decryptDataKey(kbv.getKey(), encDataKey, encKeyMeta, keyReader); }).findFirst().orElse(null); if (encKeyInfo == null || dataKey == null) { // Unable to decrypt data key return null; } return getKeyAndDecryptData(msgMetadata, payload); }
Collectors.toMap(EncryptionKeys::getKey, e -> new EncryptionKey(e.getValue().toByteArray(), e.getMetadataList() != null ? e.getMetadataList().stream().collect( Collectors.toMap(KeyValue::getKey, KeyValue::getValue)) : null)));
public ByteBuf decrypt(MessageMetadata msgMetadata, ByteBuf payload, CryptoKeyReader keyReader) { // If dataKey is present, attempt to decrypt using the existing key if (dataKey != null) { ByteBuf decryptedData = getKeyAndDecryptData(msgMetadata, payload); // If decryption succeeded, data is non null if (decryptedData != null) { return decryptedData; } } // dataKey is null or decryption failed. Attempt to regenerate data key List<EncryptionKeys> encKeys = msgMetadata.getEncryptionKeysList(); EncryptionKeys encKeyInfo = encKeys.stream().filter(kbv -> { byte[] encDataKey = kbv.getValue().toByteArray(); List<KeyValue> encKeyMeta = kbv.getMetadataList(); return decryptDataKey(kbv.getKey(), encDataKey, encKeyMeta, keyReader); }).findFirst().orElse(null); if (encKeyInfo == null || dataKey == null) { // Unable to decrypt data key return null; } return getKeyAndDecryptData(msgMetadata, payload); }
Collectors.toMap(EncryptionKeys::getKey, e -> new EncryptionKey(e.getValue().toByteArray(), e.getMetadataList() != null ? e.getMetadataList().stream().collect( Collectors.toMap(KeyValue::getKey, KeyValue::getValue)) : null)));