Tor Stem:public 键与隐藏服务描述符中的键不匹配

Tor Stem: public key don't match one in hidden servce descriptor

我正在尝试获取我创建的隐藏服务的 public 密钥。有两种方法,一种来自我的私钥,另一种是访问隐藏的服务描述符并获取 public 键字段。

我写了一个 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"))

我从私人获得的public密钥是:

-----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 的不同密钥格式。我试图使格式匹配,但我没有运气!

如何解决这个问题?

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