All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.idealo.kafka.deckard.encryption.EncryptingSerializer Maven / Gradle / Ivy

There is a newer version: 1.0.4-RELEASE
Show newest version
package de.idealo.kafka.deckard.encryption;

import org.apache.kafka.common.serialization.Serializer;
import org.springframework.security.crypto.encrypt.BytesEncryptor;
import org.springframework.security.crypto.encrypt.Encryptors;

import java.util.Map;
import java.util.Objects;

public class EncryptingSerializer implements Serializer {

    private final Serializer embeddedSerializer;
    private final BytesEncryptor bytesEncryptor;

    public EncryptingSerializer(String pass, String salt, Serializer embeddedSerializer) {
        this.embeddedSerializer = embeddedSerializer;
        this.bytesEncryptor = Encryptors.stronger(pass, salt);
    }

    @Override
    public void configure(Map map, boolean b) {
        embeddedSerializer.configure(map, b);
    }

    @Override
    public byte[] serialize(String topic, T data) {
        return Objects.nonNull(data) ? this.bytesEncryptor.encrypt(embeddedSerializer.serialize(topic, data)) : null;
    }

    @Override
    public void close() {
        embeddedSerializer.close();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy