Tor Stem:公钥与隐藏的servce描述符中的公钥不匹配

问题描述 投票:0回答:1

我试图获取我创建的隐藏服务的公钥。有两种方式,一种来自我拥有的私钥,另一种是访问隐藏的服务描述符并获取公钥字段。

我写了一个python脚本来测试它们。但是,他们是不同的!

这是脚本(pkey是从Tor控制器生成的测试私钥)

import stem
from stem.control import Controller

from Cryptodome.PublicKey import RSA

from base64 import b64encode

controller = Controller.from_port(port=9051)

controller.authenticate()

pkey="MIICXQIBAAKBgQCsqrc5jvobvNiZ4g0IdoxkQmYtFtRqGMeGCfh8IZ1s7IJ2owzrZ+8GE+HJhBr1YYFJ/9UegD9APfnybIfgmVY+PCxNlE16uMreigogAqpN4Vp8aic0s/6sXbf9EyHkafcHdMX3N3LUYhOQZfI02zNjUTRSkHp9jS+MFcWwOeYMzwIDAQABAoGANX5uZZa2RgGr2YD/KLARrr4jibSY+oXSyuQr58lCTIy5nqfFSOlaVDe0rAoRkBQ1SgfIrzpsXirVVRXqwtq+rOcRjVT4cRZnb3MNRqSFiqSocL2/TkJg97pXKfGgLkoopsGfvrgXmlpI03w8TMwbcSHvObUkC9xKqcKABtdYfQECQQDSQgyvh7YnQ2qdYeFYc9f9kT3XaUjYMgel7Zq8GAQEmsZ3YqW/vDmNVYsnQj/ZHyS/VwKFyE66jw/po+p8bBKZAkEA0jsX3AZyrd24lVkK/5gcMQLfRuOyJDtEjNXUNWxS2axUoVDBIRcArsa5IKG4yRYYRgIVSEDLxGxciTWgU5MjpwJAShTRiWskp/Ld9rPNBTBT0tjA1EwZSWtfPHxaP5mqmMC72sacJdE46e5RCDUUb/jEJtKOZfqsmpjbf3Oso8gkSQJBAJkBrUHT548nOfpojhqsSIhbQMnFWpgIEsI1tncTWdFXHVky/vzoUvThaUeYrHaeABij1314u1VAULEEOKXbBy0CQQDJJeDolidHG8UkWISq2jP6QIkpqOx3E6zxMNXAKwfz/O+yyanNtL1+MpFbk0H5n1fUhSDjR5daziUcmU93NOW9"


response = controller.create_ephemeral_hidden_service([9000, 9001],key_type ='RSA1024',key_content =pkey,await_publication=True)
onionAddr = response.service_id
#privKey  = pkey#response.private_key

print('onion: '+onionAddr)
print("\nPrivate Key: ")
print(pkey)
print("================")

pkey ="-----BEGIN RSA PRIVATE KEY-----\n"+pkey+"\n-----END RSA PRIVATE KEY-----"
privKeyObj = RSA.importKey(pkey)

#pubKey = b64encode(privKeyObj.publickey().exportKey('DER',pkcs=8))
pubKey = privKeyObj.publickey().exportKey('PEM',pkcs=1).decode()
print(pubKey)

print("\n\n\n HSD response:")
print(controller.get_hidden_service_descriptor(onionAddr+".onion"))

我从私人公钥获得的公钥是:

-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCsqrc5jvobvNiZ4g0IdoxkQmYt
FtRqGMeGCfh8IZ1s7IJ2owzrZ+8GE+HJhBr1YYFJ/9UegD9APfnybIfgmVY+PCxN
lE16uMreigogAqpN4Vp8aic0s/6sXbf9EyHkafcHdMX3N3LUYhOQZfI02zNjUTRS
kHp9jS+MFcWwOeYMzwIDAQAB
-----END PUBLIC KEY-----

隐藏服务描述符中的一个是:

-----BEGIN RSA PUBLIC KEY-----
MIGJAoGBAKyqtzmO+hu82JniDQh2jGRCZi0W1GoYx4YJ+HwhnWzsgnajDOtn7wYT
4cmEGvVhgUn/1R6AP0A9+fJsh+CZVj48LE2UTXq4yt6KCiACqk3hWnxqJzSz/qxd
t/0TIeRp9wd0xfc3ctRiE5Bl8jTbM2NRNFKQen2NL4wVxbA55gzPAgMBAAE=
-----END RSA PUBLIC KEY-----

做一些搜索引导我使用RSA的不同密钥格式。我试着让格式匹配,但我没有运气!

怎么解决这个?

python rsa tor stem pycryptodome
1个回答
0
投票

我错了,它们从一开始就是相同的,但只是不同版本的编码。 PyCryptoDome可以处理编码中的这种差异。如果两个键都导入到关键对象中并进行比较,则它们是相等的

© www.soinside.com 2019 - 2024. All rights reserved.