dlsprague commented on issue #8884:
URL: https://github.com/apache/pulsar/issues/8884#issuecomment-744565840
Here is how producer sends message.
package com.vz.apollo.alarmdbupdates;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
import org.apache.pulsar.client.api.CryptoKeyReader;
import org.apache.pulsar.client.api.EncryptionKeyInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RawFileKeyReader implements CryptoKeyReader {
protected final Logger logger =
LoggerFactory.getLogger(this.getClass());
String publicKeyFile = "";
String privateKeyFile = "";
public RawFileKeyReader(String pubKeyFile, String privKeyFile) {
publicKeyFile = pubKeyFile;
privateKeyFile = privKeyFile;
}
@Override
public EncryptionKeyInfo getPublicKey(String keyName, Map<String,
String> keyMeta) {
EncryptionKeyInfo keyInfo = new EncryptionKeyInfo();
try {
keyInfo.setKey(Files.readAllBytes(Paths.get(publicKeyFile)));
} catch (IOException e) {
logger.info("ERROR: Failed to read public key from file
" + publicKeyFile);
e.printStackTrace();
}
return keyInfo;
}
@Override
public EncryptionKeyInfo getPrivateKey(String keyName, Map<String,
String> keyMeta) {
EncryptionKeyInfo keyInfo = new EncryptionKeyInfo();
try {
keyInfo.setKey(Files.readAllBytes(Paths.get(privateKeyFile)));
} catch (IOException e) {
logger.info("ERROR: Failed to read private key from
file " + privateKeyFile);
e.printStackTrace();
}
return keyInfo;
}
}
_producer_java_client =
pulsarClient.newProducer().topic(_topic_java_client).batchingMaxPublishDelay(3,
TimeUnit.MILLISECONDS)
.cryptoKeyReader(new
RawFileKeyReader(publicKey,privateKey))
.addEncryptionKey(publicKey)
.sendTimeout(10,
TimeUnit.SECONDS).blockIfQueueFull(true)
.create();
above is the code used for encryption of the messages
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]