/opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey
Edit: /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/RSA.pyc (26795B)
Ñò
Bd\Rc @ sà d Z d Z d d d d d d g Z d d k Z e i d
d j o e i d d j o d d
k Tn d d
k Td d k l Z l Z l
Z
d d k l Z l
Z
l Z d d k l Z d d k l Z l Z l Z d d k Z d d k Z d d k l Z d d k l Z y d d k l Z Wn e j
o
e Z n Xd e i f d „ ƒ YZ d e f d „ ƒ YZ e e d ƒ e ƒ i ƒ g ƒ i ƒ Z e ƒ Z! e! i" Z" e! i# Z# e! i$ Z$ e! i% Z% d S( s† RSA public-key cryptography algorithm (signature and encryption).
RSA_ is the most widespread and used public key algorithm. Its security is
based on the difficulty of factoring large integers. The algorithm has
withstood attacks for 30 years, and it is therefore considered reasonably
secure for new designs.
The algorithm can be used for both confidentiality (encryption) and
authentication (digital signature). It is worth noting that signing and
decryption are significantly slower than verification and encryption.
The cryptograhic strength is primarily linked to the length of the modulus *n*.
In 2012, a sufficient length is deemed to be 2048 bits. For more information,
see the most recent ECRYPT_ report.
Both RSA ciphertext and RSA signature are as big as the modulus *n* (256
bytes if *n* is 2048 bit long).
This module provides facilities for generating fresh, new RSA keys, constructing
them from known components, exporting them, and importing them.
>>> from Crypto.PublicKey import RSA
>>>
>>> key = RSA.generate(2048)
>>> f = open('mykey.pem','w')
>>> f.write(RSA.exportKey('PEM'))
>>> f.close()
...
>>> f = open('mykey.pem','r')
>>> key = RSA.importKey(f.read())
Even though you may choose to directly use the methods of an RSA key object
to perform the primitive cryptographic operations (e.g. `_RSAobj.encrypt`),
it is recommended to use one of the standardized schemes instead (like
`Crypto.Cipher.PKCS1_v1_5` or `Crypto.Signature.PKCS1_v1_5`).
.. _RSA: http://en.wikipedia.org/wiki/RSA_%28algorithm%29
.. _ECRYPT: http://www.ecrypt.eu.org/documents/D.SPA.17.pdf
:sort: generate,construct,importKey,error
s $Id$t generatet constructt errort importKeyt RSAImplementationt _RSAobjiÿÿÿÿNi i i ( t *( t getRandomRanget
bytes_to_longt
long_to_bytes( t _RSAt _slowmatht pubkey( t Random( t DerObjectt DerSequencet DerNull( t inverse( t _fastmathc B sû e Z d Z d d d d d d g Z d d „ Z d „ Z d „ Z d
„ Z d „ Z d „ Z
d
„ Z d „ Z d „ Z
d „ Z d d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z d d d d „ Z RS( sl Class defining an actual RSA key.
:undocumented: __getstate__, __setstate__, __repr__, __getattr__
t nt et dt pt qt uc C s? | | _ | | _ | d j o t i ƒ i } n | | _ d S( N( t implementationt keyt NoneR
t newt readt _randfunc( t selfR R t randfunc( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/RSA.pyt __init__q s
c C sA | | i j o t | i | ƒ St d | i i | f ƒ ‚ d S( Ns %s object has no %r attribute( t keydatat getattrR t AttributeErrort __class__t __name__( R t attrname( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/RSA.pyt __getattr__x s c C s t i i | | | ƒ S( sÏ Encrypt a piece of data with RSA.
:Parameter plaintext: The piece of data to encrypt with RSA. It may not
be numerically larger than the RSA module (**n**).
:Type plaintext: byte string or long
:Parameter K: A random parameter (*for compatibility only. This
value will be ignored*)
:Type K: byte string or long
:attention: this function performs the plain, primitive RSA encryption
(*textbook*). In real applications, you always need to use proper
cryptographic padding, and you should not directly encrypt data with
this method. Failure to do so may lead to security vulnerabilities.
It is recommended to use modules
`Crypto.Cipher.PKCS1_OAEP` or `Crypto.Cipher.PKCS1_v1_5` instead.
:Return: A tuple with two items. The first item is the ciphertext
of the same type as the plaintext (string or long). The second item
is always None.
( R t encrypt( R t plaintextt K( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/RSA.pyR) € s c C s t i i | | ƒ S( sË Decrypt a piece of data with RSA.
Decryption always takes place with blinding.
:attention: this function performs the plain, primitive RSA decryption
(*textbook*). In real applications, you always need to use proper
cryptographic padding, and you should not directly decrypt data with
this method. Failure to do so may lead to security vulnerabilities.
It is recommended to use modules
`Crypto.Cipher.PKCS1_OAEP` or `Crypto.Cipher.PKCS1_v1_5` instead.
:Parameter ciphertext: The piece of data to decrypt with RSA. It may
not be numerically larger than the RSA module (**n**). If a tuple,
the first item is the actual ciphertext; the second item is ignored.
:Type ciphertext: byte string, long or a 2-item tuple as returned by
`encrypt`
:Return: A byte string if ciphertext was a byte string or a tuple
of byte strings. A long otherwise.
( R t decrypt( R t
ciphertext( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/RSA.pyR, ˜ s c C s t i i | | | ƒ S( s¹ Sign a piece of data with RSA.
Signing always takes place with blinding.
:attention: this function performs the plain, primitive RSA decryption
(*textbook*). In real applications, you always need to use proper
cryptographic padding, and you should not directly sign data with
this method. Failure to do so may lead to security vulnerabilities.
It is recommended to use modules
`Crypto.Signature.PKCS1_PSS` or `Crypto.Signature.PKCS1_v1_5` instead.
:Parameter M: The piece of data to sign with RSA. It may
not be numerically larger than the RSA module (**n**).
:Type M: byte string or long
:Parameter K: A random parameter (*for compatibility only. This
value will be ignored*)
:Type K: byte string or long
:Return: A 2-item tuple. The first item is the actual signature (a
long). The second item is always None.
( R t sign( R t MR+ ( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/RSA.pyR. ° s c C s t i i | | | ƒ S( s Verify the validity of an RSA signature.
:attention: this function performs the plain, primitive RSA encryption
(*textbook*). In real applications, you always need to use proper
cryptographic padding, and you should not directly verify data with
this method. Failure to do so may lead to security vulnerabilities.
It is recommended to use modules
`Crypto.Signature.PKCS1_PSS` or `Crypto.Signature.PKCS1_v1_5` instead.
:Parameter M: The expected message.
:Type M: byte string or long
:Parameter signature: The RSA signature to verify. The first item of
the tuple is the actual signature (a long not larger than the modulus
**n**), whereas the second item is always ignored.
:Type signature: A 2-item tuple as return by `sign`
:Return: True if the signature is correct, False otherwise.
( R t verify( R R/ t signature( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/RSA.pyR0 É s c C s | i i | ƒ f S( N( R t _encrypt( R t cR+ ( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/RSA.pyR2 ß s c C si | d \ } t d | i i d d | i ƒ} | i i | | ƒ } | i i | ƒ } | i i | | ƒ S( Ni R ( R R R R t _blindt _decryptt _unblind( R R3 R- t rt cpt mp( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/RSA.pyR5 â s
"c C s | i i | | ƒ S( N( R R4 ( R t mR7 ( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/RSA.pyR4 ó s c C s | i i | | ƒ S( N( R R6 ( R R: R7 ( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/RSA.pyR6 ö s c C s | i i | ƒ f S( N( R t _sign( R R: R+ ( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/RSA.pyR; ù s c C s | d \ } | i i | | ƒ S( Ni ( R t _verify( R R: t sigt s( ( sG /opt/alt/python27/lib64/python2.7/site-packages/Crypto/PublicKey/RSA.pyR<