简体   繁体   English

如何使用 python 中的公钥验证私钥

[英]How to validate a private key using a public key in python

I was wondering how I use a public key to validate a private key.我想知道如何使用公钥来验证私钥。

I have absolute no idea what I am doing我完全不知道我在做什么

I am given a public key in the form:我得到了一个公钥,格式如下:

" <RSAKeyValue><Modulus>tuRctbsnB4OSsR7gqNy1ovYZ4vDTn543o4ldX8Wthfjk7dAQKPHQYUmB7EyC4qFQ2GY3/Q+mDjJBDCWbsb8gyFuyU3L93UJ/7szvO+2A/t520srjCN4Yv7HirgpAI0LaWlo1UUUixMU2+kYNv/kBeVUL47TvOIpm0JqstQVDHhJtNMwcbY+3Q0nN4D1jNkSrQitCF3Sdms1kwsIFcdHcUh3WcUBkIefcB97DZKVY915IFbhf1/xdpPBa/E0WjNgtF5q4FI5ClH2CxsDwy2mL6qzZMvRPNWUhaFKlX+CcGvFQOtuJ4K8PZ0P3Wsq55ccxafZp3BQrEcBbto5Cll/E0Q==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue> " " <RSAKeyValue><Modulus>tuRctbsnB4OSsR7gqNy1ovYZ4vDTn543o4ldX8Wthfjk7dAQKPHQYUmB7EyC4qFQ2GY3/Q+mDjJBDCWbsb8gyFuyU3L93UJ/7szvO+2A/t520srjCN4Yv7HirgpAI0LaWlo1UUUixMU2+kYNv/kBeVUL47TvOIpm0JqstQVDHhJtNMwcbY+3Q0nN4D1jNkSrQitCF3Sdms1kwsIFcdHcUh3WcUBkIefcB97DZKVY915IFbhf1/xdpPBa/E0WjNgtF5q4FI5ClH2CxsDwy2mL6qzZMvRPNWUhaFKlX+CcGvFQOtuJ4K8PZ0P3Wsq55ccxafZp3BQrEcBbto5Cll/E0Q==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue> "

which is a string and I am trying to validate a private key (which is also provided as a string) with it using python.这是一个字符串,我正在尝试使用 python 验证私钥(也作为字符串提供)。 I know what the issuer and audience needs to be but I'm not sure what to do with all this information.我知道发行人和受众需要是什么,但我不确定如何处理所有这些信息。

I have looked at some peoples examples of using various packages but I can't seem to figure out what type pub_key, private_key, and message would be... Please help me... I wish to learn我看过一些人使用各种包的例子,但我似乎无法弄清楚 pub_key、private_key 和消息是什么类型......请帮助我......我想学习

Base 64 decode the components - modulus and public exponent - of the public key from within the XML and create the public key from the decoded unsigned, big endian number values. Base 64 从 XML 中解码公钥的组件 - 模数和公共指数 - 并从解码的无符号大端数字值创建公钥。

Then create a signature with the private key over any data and verify it with the public key using the same RSA signature algorithm such as RSA with PKCS#1 v1.5 padding.然后使用私钥在任何数据上创建签名,并使用相同的 RSA 签名算法(例如带有 PKCS#1 v1.5 填充的 RSA)使用公钥对其进行验证。 If it verifies, the keys form a key pair.如果它验证,则密钥形成密钥对。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM