Trying to generate RSA signature with Python from working C# code

元气小坏坏 提交于 2019-12-08 05:37:40

ok, first: long in python is not 4 byte. in python, long has no predefined size, so using a long to store a 128byte number is no problem. to convert a bytestring to long you can use:

long_value = long(string_value.decode('hex'), 16)
# maybe someone knows a better way?

couldn't it be that the file is in DER form? in that case you simply could simple read the file using:

from Crypto.PublicKey import RSA
with open("keyfile", "rb") as f:
    key = RSA.importKey(f.read())

if not, it would probably be best to convert it to PEM or DER, so you don't have to read in the parameters yourself. anyway, the last three parameters in RSA.construct are optional, specially u can be calculated as 1/p % q (where p > q). at least from what i've tried, it works even if you only specify the first three parameters.

I tried pycrypto and another library, but only ended getting what I wanted working with M2Crypto.

M2Crypto was a serious pain to install on Windows, but it was really easy with the install file here:

http://chandlerproject.org/bin/view/Projects/MeTooCrypto

The download link the to Windows installer is here: http://chandlerproject.org/pub/Projects/MeTooCrypto/M2Crypto-0.21.1.win32-py2.7.exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!