m2crypto

Python M2Crypto - generating a DSA key pair and separating public/private components

Could anybody explain what is the cause of the following: >>> from M2Crypto import DSA, BIO >>> dsa = DSA.gen_params(1024) ..+........+++++++++++++++++++++++++++++++++++++++++++++++++++* ............+.+.+..+.........+.............+.....................+. ...+.............+...........+......................................... +.........+...

Python M2Crypto EC Support

M2Crypto provides EC support for ECDSA/ECDH. I have installed OpenSSL 0.9.8i which contains support for EC. However when I run "from M2Crypto import EC,BIO" I get error saying EC_init() failed. So I added debug to print m2.OPENSSL_VERSION_TEXT value. It gets printed as "OpenSSL 0.9.7 19 Feb 2003". This version of OpenSSL doesnot support ...

M2Crypto Encrypt/Decrypt using AES256

Can someone provide me code to encrypt / decrypt using m2crypto aes256 CBC using Python ...

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

Hi all, 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? Thanks a lot, hevalbaranov ...

How to use .pem file with Python M2Crypto

To generate an RSA key pair I used openssl: openssl genrsa -out my_key.private.pem 1024 openssl rsa -in my_key.private.pem -pubout -out my_key.public.pem Now I want to use this my_key.public.pem file in a function of another .py file: import M2Crypto from M2Crypto import RSA,SSL def encrypt(): pk = open( 'my_key.public.pem', 'rb...

m2crypto throws "TypeError: in method 'x509_req_set_pubkey'"

Guys, my little code snippet throws the following Traceback: ..++++++++++++ ..++++++++++++ Traceback (most recent call last): File "csr.py", line 48, in <module> csr.create_cert_signing_request(pubkey, cert_name) File "csr.py", line 17, in create_cert_signing_request cert_request.set_pubkey(EVP.PKey(keypair)) File "/usr/li...

file accessing in load_pub_key

Consider the code: fileHandle = open ( 'test8.pem','w' ) fileHandle.write (data) pub_key = M2Crypto.RSA.load_pub_key(open('test8.pem')) Error coming like : File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 343, in load_pub_key bio = BIO.openfile(file) File "/usr/lib/python2.4/site-packages/M2Crypto/BIO.py", line 186,...

java to python conversion: x509 / dsa / sha1withdsa crypto howto?

I've got the following Java code that I'm trying to convert to python, and I'm not really sure how to do this: import java.security.spec.X509EncodedKeySpec; import java.security.KeyFactory; import java.security.PublicKey; import java.security.Signature; byte[] key = KeyReader.read(filestream) //KeyReader.read(inputstream) just reads...

How do you verify an RSA SHA1 signature in pyOpenSSL

Hi, I tried installing M2Crypto and facing problems. I don't want to force my customers to use such libraries which are difficult to install. So, I thought I would give pyOpenSSL a try. I am able to get the public key from pem certificate but am not able to find any way to verify the signature. ...

How to disable URL redirection in Python when using M2Crypto SSL?

This is what my code looks like: url_object = urlparse(url) hostname = url_object.hostname port = url_object.port uri = url_object.path if url_object.path else '/' ctx = SSL.Context() if ctx.load_verify_locations(cafile='ca-bundle.crt') != 1: raise Exception("Could not load CA certificates.") ctx.set_verify(SSL.verify_peer | SSL.verify...

How to sign a document in python with M2Crypto using particular padding technique?

I need to digitally sign some text in python using a private key stored in a .pem file. It seems like M2Crypto is the preferred way to do that these days, so that's what I'm using. I think I get most of it, but I'm confused about how to configure padding. To be specific, I need to verify the signature in an iPhone app, using a padding ...

Java to Python RSA

I'm trying to encrypt a string from Java to Python, using the library Bouncy Castle J2ME on the client side and Python M2Crypto on the other. Everything is pretty good, I can decrypt it properly, but the padding is the issue. The M2Crypto lib gives me (as far as I can tell) only these Padding schemes: no_padding = 3 pkcs1_padding = 1 s...

What is the difference between M2Crypto's set_client_CA_list_from_file() and load_verify_info() and when would you use each?

The M2Crypto library has a few CA-related functions on its SSL.Context object, but the documentation is very unclear as to when you would use certain functions and why. In fact, the docs for almost all of them are, "Load CA certs into the context," so it seems possible that they all do the same thing. There are several examples that us...

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

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.do...

What to put for a commonName when making an OpenSSL key?

I have an application application framework that works in a peer-to-peer manner between unnamed hosts on a network. I want to have the traffic be encrypted, so I've implemented a setup with M2Crypto, but I've run into a snag. I have no idea what to put down for 'commonName' when creating the cert. It seems to want a domain name, but none...

m2crypto custom certificate verification

I need to build an encrypted connection between two peers, and I need to authenticate both. Both peers already share a fingerprint (SHA256 hash) of the other peer public key. I'm not using X509 or OpenPGP keys/certs as they are too big and bulky for my needs and they don't fit in the security model. I'm trying to build a connection with...

M2Crypto: AttributeError for load_dynamic_engine()

I am using M2Crypto-0.20.2. I want to use engine_pkcs11 from the OpenSC project and the Aladdin PKI client for token based authentication making xmlrpc calls over ssl. I am trying to load the PKCS#11 engine as well as the Aladdin module (see code below). But I get an error: AttributeError: 'module' object has no attribute 'load_dynami...

Need help using M2Crypto.Engine to access USB Token

I am using M2Crypto-0.20.2. I want to use engine_pkcs11 from the OpenSC project and the Aladdin PKI client for token based authentication making xmlrpc calls over ssl. from M2Crypto import Engine Engine.load_dynamic() dynamic = Engine.Engine('dynamic') # Load the engine_pkcs from the OpenSC project dynamic.ctrl_cmd_string("SO_PATH", "/...

M2Crypto: API Question on Engine Class

Hello, The following 3 Engine methods require 'name' as an argument. load_private_key(self, name, pin=None) load_public_key(self, name, pin=None) load_certificate(self, name) What exactly is 'name'? From examples I've found it appears to be some type of slot id for the USB token. How do I find the id? Thanks! ...

How to verify ECDSA/SHA2 S-MIME signature with python ?

We need to choose between two signature schemes: RSA/SHA2 S-MIME signatures ECDSA/SHA2 S-MIME signatures For that our python software needs to support one of this scheme. Currently for some political reasons the ECDSA solution is prefered. Is the ECDSA solution supported by any of the python crypto modules (M2Crypto, ...) and do you...