我的团队正在使用 confluent_kafka 生成实时流,并使用自定义加密被推送到队列中。背后的技术是Java。
我正在尝试使用主题中的 python 来使用消息,并且能够这样做但无法使用 python 对其进行解密。
from confluent_kafka import *
import os
from confluent_kafka.serialization import StringDeserializer
os.environ['HTTPS_PROXY'] = "http://username:password@proxy.com:8080"
c = DeserializingConsumer({
'bootstrap.servers': 'kafka.abcd.com:1010',
'group.id':'SharedKafka2',
'auto.offset.reset': 'latest',
'security.protocol':'SSL',
'ssl.ca.location':'CARoot.pem',
'ssl.certificate.location':'certificate.pem',
'ssl.key.location':'key.pem',
'value.deserializer': StringDeserializer()
})
c.subscribe(['SharedKafka2_Topic'])
print("ConsumerStarted")
while True:
msg = c.poll()
if msg is None:
continue
if msg.error():
if msg.error().code() == KafkaError._PARTITION_EOF:
continue
else:
print(msg.error())
break
print(msg.value())
输出=b'\x85s\n\x0e{!G\xc7\xdfaV\x8e\x03a\xc4\x8e\xe1\xbc\xf4\xf4F\xb5<{\xecD\xc2\xf8jNN
我无法在值反序列化器中提供自定义加密密钥。以下是它在java中的实现方式:
props.put("key.deserializer","com.aexp.sec.kafka.serializers.CryptoDeSerializer");
props.put("value.deserializer","com.aexp.sec.kafka.serializers.CryptoDeSerializer");
props.put("CRYPTO_KEY_DESERIALIZER", StringDeserializer.class.getName());
props.put("CRYPTO_VALUE_DESERIALIZER", StringDeserializer.class.getName());
**props.put(String.format("%s_APIGEE_ENDPOINT", topic), apigeeUrl);
props.put("ENVIRONMENT", environment);
props.put(String.format("%s_KEY_IDENTIFIER", topic), keyIdentifier);
props.put(String.format("%s_APIGEE_CLIENT_ID", topic), clientID);
props.put(String.format("%s_APIGEE_CLIENT_SECRET", topic), clientSecret);**
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
while (true) {
ConsumerRecords<String, String> records = consumer.poll(1000);
for (ConsumerRecord<String, String> record : records) {
buff.write(record.value()+"\n");
buff.flush();
}
}
如何使用 python 自定义解密来解密字符串格式?