Can someone recommend a library for calculating SHA1WithRSAEncryption in Python?
Context: I'm trying to do some message authentication. I've looked at PyXMLDSig, but it seemed to expect the certificates as separate files. As a first step to better understanding the problem space, I wanted to calculate the digest values "by hand".
I've looked around and seen Java implementations, but not Python ones. (Jython isn't really an option for my environment.)
Thanks in advance.
Take a look at M2Crypto, it's probably the best and most complete crypto library for Python.
Related
I just had started my studies about SSL recently and I need to create a RSA key pairs, then use'em to create a CSR. It must be done in Python, due my projects needs.
I took a look around several libs and their documentations, as also websites, blogs and some books too, but everything I've found is or only at Linux (which help me to understand better about SSL) or not exacly what I'm looking for.
I also gonna need to validate certificate chains and learn about HTTP GET using HTTPS with certification, but I can take care of that later.
(I don't know, it looks basic stuff but I ain't figuring out anyways)
Any help will be welcome and I'm sorry if I wasn't clear enough.
Ok, the idea of using PKIutils lib made his effort. I could not installed in the beginning in order of some problems and issues with Python (2.7), but they are now solved.
This lib is really the thing I was looking for and is very simple once it does his job in a basic way with a proportional effort.
As we can see in its docs (http://python-pkiutils.readthedocs.io/en/latest/), we just need to call as the example:
key = pkiutils.create_rsa_key(1024, keyfile='')
csr = pkiutils.create_csr
(key,
dn="/C=GB/ST=STATENAME/L=LOCAILITY/O=COMPANY/OU=DEPT/CN=www.example.com",
csrfilename='')
This is just an example, of course, but it creates the RSA pair and the CSR anyways.
Solved my problem; maybe it can be useful for somebody else.
I am trying to do some research on the wikipedia data, I am good at Python.
I came across this library, seems nice: https://pypi.python.org/pypi/wikipedia/
I don't want to hit wikipedia directly as this is slow, and also I am trying to access a lot of data and might run into their API limits.
Can I somehow hack this to make it access a local instance of wikipedia data. I know I can run a whole wikipedia server and try to do that, but that seems a round about way.
Is there a way to just point to the folder and get this library to work as it does. Or are you aware of any other libraries that do this?
thank you.
I figured out what I need. I think I shouldn't be searching for API, what I am looking for is a parser. Here are a couple options I have narrowed down so far. Both seem like solid starting points.
wikidump:
https://pypi.python.org/pypi/wikidump/0.1.2
mwlib:
https://pypi.python.org/pypi/mwlib/0.15.14
Update: While these are good parsers for wikipedia data, I found them too limiting in one way or the other, not to mention the lack of documentation. So I eventually went with good old python ElementTree and directly work with the XML.
I'm given a task of converting a bunch of codes written in Python 2.7 into Python 3.
So my question is
What are the fundamental differences between the two and what are the new features expected from conversion? I'm assuming it's not just syntactical issues.
Where should I start and what should I focus on?
It'll be more helpful if you could be as concrete as possible..
Please help me out and thank you in advance
Definitely start here: http://docs.python.org/py3k/whatsnew/3.0.html
For an automated tool, see: http://docs.python.org/library/2to3.html
Building from Greg's answer I find find it easier to grok the changes by looking at different compatibility layers people have built in order to support 2 and 3 in parallel.
CherryPy, or specifically this file.
Six, or specifically this file.
Pyramid, or specifically this file.
To use a compatibility layer or not is a widely discussed topic, however they are a good programmatic reference too scope the major changes and what you need to do in order to support them.
By far the easiest way is to use 2to3 and maintain two branches concurrently for a while. See this article on the python.org wiki.
There's also an entire website with detailed information, which is basically the contents of a book on the subject.
I am trying to learn Python and referencing the documentation for the standard Python library from the Python website, and I was wondering if this was really the only library and documentation I will need or is there more? I do not plan to program advanced 3d graphics or anything advanced at the moment.
Edit:
Thanks very much for the responses, they were very useful. My problem is where to start on a script I have been thinking of. I want to write a script that converts images into a web format but I am not completely sure where to begin. Thanks for any more help you can provide.
For the basics, yes, the standard Python library is probably all you'll need. But as you continue programming in Python, eventually you will need some other library for some task -- for instance, I recently needed to generate a tone at a specific, but differing, frequency for an application, and pyAudiere did the job just right.
A lot of the other libraries out there generate their documentation differently from the core Python style -- it's just visually different, the content is the same. Some only have docstrings, and you'll be best off reading them in a console, perhaps.
Regardless of how the other documentation is generated, get used to looking through the Python APIs to find the functions/classes/methods you need. When the time comes for you to use non-core libraries, you'll know what you want to do, but you'll have to find how to do it.
For the future, it wouldn't hurt to be familiar with C, either. There's a number of Python libraries that are actually just wrappers around C libraries, and the documentation for the Python libraries is just the same as the documentation for the C libraries. PyOpenGL comes to mind, but it's been a while since I've personally used it.
As others have said, it depends on what you're into. The package index at http://pypi.python.org/pypi/ has categories and summaries that are helpful in seeing what other libraries are available for different purposes. (Select "Browse packages" on the left to see the categories.)
One very common library, that should also fit your current needs, is the Python Image Library (PIL).
Note: the latest version is still in beta, and available only at Effbot site.
If you're just beginning, all you'll need to know is the stuff you can get from the Python website. Failing that a quick Google is the fastest way to get (most) Python answers these days.
As you develop your skills and become more advanced, you'll start looking for more exciting things to do, at which point you'll naturally start coming across other libraries (for example, pygame) that you can use for your more advanced projects.
It's very hard to answer this without knowing what you're planning on using Python for. I recommend Dive Into Python as a useful resource for learning Python.
In terms of popular third party frameworks, for web applications there's the Django framework and associated documentation, network stuff there's Twisted ... the list goes on. It really depends on what you're hoping to do!
Assuming that the standard library doesn't provide what we need and we don't have the time, or the knowledge, to implement the code we reuse 3rd party libraries.
This is a common attitude regardless of the programming language.
If there's a chance that someone else ever wanted to do what you want to do, there's a chance that someone created a library for it. A few minutes Googling something like "python image library" will find you what you need, or let you know that someone hasn't created a library for your purposes.
Of course similar questions have been asked in stackoverflow but I don't want to use any third party library like Crypto or something. So I need to generate a ciphertext from a user email and decrypt it back to plaintext. How can I do this in python?
A third-party system is your best bet.
If you really can't/don't want to use a third-party, maybe something simple would suffice.
One of the simpler algorithms is the Tiny Encryption Algorithm (TEA). Here's an example of a Python implementation that you could start with.
Yes, you can.
Read http://www.amk.ca/python/code/crypto.html
You'll find an answer there ;)
You're question is not concrete enough to say more. You may want to read http://en.wikipedia.org/wiki/Cryptography#Modern_cryptography
Cheers,
Tuergeist
Update:
No, you cannot. (with build in functionality due to export restrictions, see http://docs.python.org/library/crypto.html)
But you can, if you're implementing you own algorithm (bad idea).
So, the BEST solution is, to use the extension recommended by python core developers. See post above.
Cheers again.
If what you mean is that you want to roll your own encryption system, you could try using the built-in hmac and hashlib modules. (hashlib is new for 2.5, so if you must use an earlier Python, your hash choices are the older md5 and sha modules.)
If you are opposed to (or are prevented from) installing a third-party library but are OK with using third-party algorithms or even "lightweight" third-party implementations of algorithms (e.g. published Python source code which resides in a single .py file that you can incorporate or import yourself without using setup.py or any other formal installation), then I highly recommend you do so, because these are likely to be better than what you can come up with on your own.
The smallest and user-friendliest of these that I am aware of is known as p3, written by cryptographer Paul Rubin. The original link is no longer active but you can search for it. Googling currently yields a near-exact copy as well as an adaptation for Python 3.
You could also try one of several single-module, pure-Python Rijndael (AES) implementations such as this or this. (Again, links are not guaranteed to be permanent so you may have to do some searching.)