我有一个消息用.Net RSACryptoServiceProvider签名,然后将消息发送到 Python软件,它试图用m2crypto(基于openssl的lib)验证符号。RSACryptoServiceProvider消息签名验证与m2crypto
我已经得到了公共证书,这是用于签名消息的私钥对。
.NET软件发送之前唱使用ByteArrayToString,因为是用下面的代码生成的符号转换:
//Convert plain text into a byte array to sign.
byte[] data = new UTF8Encoding().GetBytes(phrase);
SHA1Managed sha1 = new SHA1Managed();
byte[] hashBytes = sha1.ComputeHash(data);
byte[] sig = csp.SignData(hashBytes, CryptoConfig.MapNameToOID("SHA1"));
所以sended到接收器的签名是
ByteArrayToString(sig)
的Python部分是:
def verify(message, signature, cert_path):
msg = hashlib.sha1(message).hexdigest()
certificate = M2Crypto.X509.load_cert(cert_path)
pubkey = certificate.get_pubkey()
pubkey.reset_context(md='sha1')
pubkey.verify_init()
pubkey.verify_update(msg)
sgn = signature.decode('base64')
is_verified = pubkey.verify_final(sgn)
而且我无法获得验证离子...我认为Python部分中的签名编码可能存在问题,但也许有人可以看到其他任何错误?
当我用我自己的证书(OpenSSL的生成),并签署从Python本身的消息,编码签名,发送,然后解码和验证一切正常......
我将不胜感激任何注释!
谢谢Jcs - 我刚刚找到了你的答案。我的客户向我提供了两次消息......但他的IT部门忘了告诉我这件事.. – sebzur 2016-01-19 09:41:21