T - public class CryptoSerializer<T> extends Object implements org.apache.kafka.common.serialization.ExtendedSerializer<T>
Serializer for encrypted
Data is first serialized with the underlying serializer
If a key reference is found either in the Kafka Header KafkaCryptoConstants.KEY_REF_HEADER,
or in the ThreadLocal keyRefHolder, then the serialized data is encrypted using the Encryptor.
If data has been encrypted, the result of the serialization is a byte array having the following structure:
magic_bytes(KafkaCryptoConstants.ENCRYPTED_PREFIX)(6 bytes)|keyref.length(4 bytes)|keyref|encrypted_data
If the result of encryption is null, then the result of serialization will be null.
If no key reference was found, the result of serialization will be directly the output of the underlying Serializer.
Please note that this Serializer has no default constructor, so it can not be configured via properties.
So if you want to use it into a Producer, you will have to use org.apache.kafka.clients.producer.KafkaProducer#KafkaProducer(Properties, Serializer, Serializer)
or org.apache.kafka.clients.producer.KafkaProducer#KafkaProducer(Map, Serializer, Serializer) with your
instance of CryptoDeserializer
| Constructor and Description |
|---|
CryptoSerializer(org.apache.kafka.common.serialization.ExtendedSerializer<? super T> rawSerializer,
Encryptor encryptor,
ThreadLocal<byte[]> keyRefHolder) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
configure(Map<String,?> configs,
boolean isKey) |
byte[] |
serialize(String topic,
org.apache.kafka.common.header.Headers headers,
T data)
serialize data with encryption (if needed).
|
byte[] |
serialize(String topic,
T data)
serialize data with encryption (if needed).
|
public CryptoSerializer(org.apache.kafka.common.serialization.ExtendedSerializer<? super T> rawSerializer, Encryptor encryptor, ThreadLocal<byte[]> keyRefHolder)
rawSerializer - Serializer to serialize data before encryptionencryptor - Encryptor to encrypt datakeyRefHolder - ThreadLocal used to communicate the key reference when using Kafka Stream (unused for regular Kafka Producer)public byte[] serialize(String topic, org.apache.kafka.common.header.Headers headers, T data)
KafkaCryptoConstants.KEY_REF_HEADERserialize in interface org.apache.kafka.common.serialization.ExtendedSerializer<T>topic - headers - data - public byte[] serialize(String topic, T data)
keyRefHolderserialize in interface org.apache.kafka.common.serialization.Serializer<T>topic - data - public void configure(Map<String,?> configs, boolean isKey)
configure in interface org.apache.kafka.common.serialization.Serializer<T>public void close()
close in interface Closeableclose in interface AutoCloseableclose in interface org.apache.kafka.common.serialization.Serializer<T>Copyright © 2018. All rights reserved.