m2crypto

How to recreate the following signing cmd-line OpenSSL call using M2Crypto in Python?

谁都会走 提交于 2019-12-10 17:23:34
问题 This works perfectly in command-line, I would like to do the same using M2Crypto in Python code. openssl smime -binary -sign -signer certificate.pem -inkey key.pem \ -in some_file.txt -out signed_file -outform DER \ -passin pass:somepassword 回答1: This is how I have been using M2Crypto to sign a file. text = open('/path/to/some_file.txt').read() passphrase = 'somepassword' buffer = M2Crypto.BIO.MemoryBuffer(text) signer = M2Crypto.SMIME.SMIME() signer.load_key('/path/to/key.pem', '/path/to

M2Crypto: verifying DSA signatures

你说的曾经没有我的故事 提交于 2019-12-07 22:53:23
问题 I'm having trouble verifying DSA signatures using Python/M2Crypto. The signatures are generated in Java, using standard java.security.Signature class, with Sun's crypto provider and SHA1withDSA algorithm designation. Here's some shell output: >>> pk <M2Crypto.DSA.DSA_pub instance at 0x20b6a28> >>> sig = '302c02141c4bbb218215ebfec57288059ce814dc430d849502144dd0c581bf2213aff79d17eb37c939e120a97bd2'.decode('hex') >>> data ='0501...9794'.decode('hex') >>> pk.verify_asn1(sig, data) ---------------

How can I create a RSA public key in PEM format from an RSA modulus?

谁说我不能喝 提交于 2019-12-07 19:13:43
问题 I have the modulus of an RSA public key. I want to use this public key with the Python library "M2Crypto", but it requires a public key in PEM format. Thus, I have to convert the RSA modulus to a PEM file. The modulus can be found here. Any ideas? 回答1: The M2Crypto library has a way to reconstruct a public key. You need to know the public exponent, e (often 65337 for RSA keys, but other numbers such as 3 or 17 have been used), and the modulus, n (which is the 512-bit number provided in the

Installing M2Crypto on Windows

陌路散爱 提交于 2019-12-07 17:10:50
问题 I am trying to install M2Crypto on a Windows 7 machine using easy_install. However, I get the following error: SWIG_m2crypto.i(31) : Error: Unable to find 'openssl\opensslv.h' SWIG_m2crypto.i(45) : Error: Unable to find 'openssl\safestack.h' SWIG_evp.i(12) : Error: Unable to find 'openssl\opensslconf.h' SWIG_ec.i(7) : Error: Unable to find 'openssl\opensslconf.h' error: Setup script exited with error: command 'swig.exe' failed with exit status 1 Any advice? i tried installing openssl for

m2crypto aes-256-cbc not working against encoded openssl files

﹥>﹥吖頭↗ 提交于 2019-12-06 15:27:06
$ echo 'this is text' > text.1 $ openssl enc -aes-256-cbc -a -k "thisisapassword" -in text.1 -out text.enc $ openssl enc -d -aes-256-cbc -a -k "thisisapassword" -in text.enc -out text.2 $ cat text.2 this is text I can do this with openssl. Now, how do I do the same in m2crypto. Documentation is lacking this. I looked at the snv test cases, still nothing there. I found one sample, http://passingcuriosity.com/2009/aes-encryption-in-python-with-m2crypto/ (changed to aes_256_cbc), and it will encrypted/descrypt it's own strings, but it cannot decrypt anything made with openssl, and anything it

Gen public key from xml data file using M2Crypto for signature verification

╄→гoц情女王★ 提交于 2019-12-06 09:23:24
I have pub key in xml format: <RSAKeyValue><Modulus>xF9y25EXh8n99sXtU/JAsYTwML6PB7gSCE8tWw8Www2KBfDqohQBL8FMs8jzsDQa7WwoEmiVJ1resEC9YXJGbwQyWgb9qgooC9oSnCB/TkRdBybwby0DKuZOzq+609OBGkwWpgnS4QVCBc6eW+10l3qE3/2hKdcSV+08iRYp7zs=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue> So i try thms like this: from M2Crypto import RSA from xml.dom.minidom import parseString import base64 dom = parseString(pubKey) e = base64.b64decode(dom.getElementsByTagName('Exponent')[0].childNodes[0].data) n = base64.b64decode(dom.getElementsByTagName('Modulus')[0].childNodes[0].data) rsa = RSA.new_pub_key((e, n)) Got

M2Crypto: verifying DSA signatures

泪湿孤枕 提交于 2019-12-06 08:29:37
I'm having trouble verifying DSA signatures using Python/M2Crypto. The signatures are generated in Java, using standard java.security.Signature class, with Sun's crypto provider and SHA1withDSA algorithm designation. Here's some shell output: >>> pk <M2Crypto.DSA.DSA_pub instance at 0x20b6a28> >>> sig = '302c02141c4bbb218215ebfec57288059ce814dc430d849502144dd0c581bf2213aff79d17eb37c939e120a97bd2'.decode('hex') >>> data ='0501...9794'.decode('hex') >>> pk.verify_asn1(sig, data) ------------------------------------------------------------ Traceback (most recent call last): ... DSAError: wrong

Timestamp server rfc3161 response token generation in Python

感情迁移 提交于 2019-12-06 06:41:21
问题 I'm trying to implement tsa server on python using twisted. Currently I'm using openssl binary to generate response, but this seems ugly to me, that's why I'm trying to figure out how to make response token with m2crypto. Thanks in advance for help! Maris. EDITED: how to achieve with m2crypto?: openssl ts -reply -section tsa_config1 -queryfile query.tsq -out response.tsr 回答1: M2Crypto does not yet wrap those pieces of openssl, so you can't use M2Crypto for what you are using the openssl

M2crypto signature “algorithm”

纵饮孤独 提交于 2019-12-06 02:50:57
问题 These two codes provide the same signature, which is expected: code1: from M2Crypto import RSA, EVP import base64, hashlib text = "some text" pkey = EVP.load_key("mykey.pem") #"mykey.pem" was generated as: openssl genrsa -des3 -out mykey.pem 2048 pkey.sign_init() pkey.sign_update(text) signature = pkey.sign_final() print base64.b64encode(signature) code2: pkey = RSA.load_key("mykey.pem") signature = pkey.sign(hashlib.sha1(text).digest()) print base64.b64encode(signature) However, if I want to

Installing M2Crypto on Windows

走远了吗. 提交于 2019-12-05 19:31:04
I am trying to install M2Crypto on a Windows 7 machine using easy_install. However, I get the following error: SWIG_m2crypto.i(31) : Error: Unable to find 'openssl\opensslv.h' SWIG_m2crypto.i(45) : Error: Unable to find 'openssl\safestack.h' SWIG_evp.i(12) : Error: Unable to find 'openssl\opensslconf.h' SWIG_ec.i(7) : Error: Unable to find 'openssl\opensslconf.h' error: Setup script exited with error: command 'swig.exe' failed with exit status 1 Any advice? i tried installing openssl for windows. yossi There is a Windows Installer in the M2Crypto page. Unable to install using easy_install on