Module: SSLCrypto
SSLCrypto - partial Python wrapper for SSL crypto
Contains an abstract class called key, which provides
an effortlessly simple API for most common crypto operations.
An almost totally-compatible replacement for ezPyCrypto
Also, features an implementation of ElGamal
Class: DictType
dict() -> new empty dictionary.
dict(mapping) -> new dictionary initialized from a mapping object's
(key, value) pairs.
dict(seq) -> new dictionary initialized as if via:
d = {}
for k, v in seq:
d[k] = v
dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
Methods for class DictType
DictType.clear()
D.clear() -> None. Remove all items from D.
DictType.copy()
D.copy() -> a shallow copy of D
DictType.fromkeys()
dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.
v defaults to None.
DictType.get()
D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.
DictType.has_key()
D.has_key(k) -> 1 if D has a key k, else 0
DictType.items()
D.items() -> list of D's (key, value) pairs, as 2-tuples
DictType.iteritems()
D.iteritems() -> an iterator over the (key, value) items of D
DictType.iterkeys()
D.iterkeys() -> an iterator over the keys of D
DictType.itervalues()
D.itervalues() -> an iterator over the values of D
DictType.keys()
D.keys() -> list of D's keys
DictType.pop()
D.pop(k[,d]) -> v, remove specified key and return the corresponding value
If key is not found, d is returned if given, otherwise KeyError is raised
DictType.popitem()
D.popitem() -> (k, v), remove and return some (key, value) pair as a
2-tuple; but raise KeyError if D is empty
DictType.setdefault()
D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D
DictType.update()
D.update(E) -> None. Update D from E: for k in E.keys(): D[k] = E[k]
DictType.values()
D.values() -> list of D's values
Class: ElGamal
None
Methods for class ElGamal
ElGamal.construct()
construct(tuple:(long,long,long,long)|(long,long,long,long,long)))
: ElGamalobj
Construct an ElGamal key from a 3- or 4-tuple of numbers.
ElGamal.decrypt()
decrypt(ciphertext:tuple|string|long): string
Decrypt 'ciphertext' using this key.
ElGamal.encrypt()
encrypt(plaintext:string|long, K:string|long) : tuple
Encrypt the string or integer plaintext. K is a random
parameter required by some algorithms.
ElGamal.generateKey()
generate(bits:int, progress_func:callable, **kw)
Generate an ElGamal key of length 'bits', using 'randfunc' to get
random data and 'progress_func', if present, to display
the progress of the key generation.
Keywords:
- privbytes - if given, causes the private key (.x), when represented
as a binary string, to be exactly this many bytes long
ElGamal.genk()
Generate a 'K' value for signing/encrypting
ElGamal.hasPrivateKey()
Returns True if private key is present in this key object (and therefore the
key object is capable of decryption), or False if not.
ElGamal.importPrivKey()
importPubKey - import private key parameters
Arguments:
- (p, g, y, x), as a tuple (as returned by privKey())
ElGamal.importPubKey()
Import someone else's public key
Arguments:
- (p, g, y), a tuple (as returned by pubKey())
ElGamal.maxSize()
Returns the maximum allowable size of plaintext strings which can
be encrypted
ElGamal.privKey()
Return tuple containing the public and private information.
ElGamal.pubKey()
Return tuple containing only the public information.
ElGamal.sign()
sign(M : string|long, K:string|long) : tuple
Return a tuple containing the signature for the message M.
K is a random parameter required by some algorithms.
ElGamal.verify()
verify(M:string|long, signature:tuple) : bool
Verify that the signature is valid for the message M;
returns true if the signature checks out.
Class: IntType
int(x[, base]) -> integer
Convert a string or number to an integer, if possible. A floating point
argument will be truncated towards zero (this does not include a string
representation of a floating point number!) When converting a string, use
the optional base. It is an error to supply a base when converting a
non-string. If the argument is outside the integer range a long object
will be returned instead.
Class: ListType
list() -> new list
list(sequence) -> new list initialized from sequence's items
Methods for class ListType
ListType.append()
L.append(object) -- append object to end
ListType.count()
L.count(value) -> integer -- return number of occurrences of value
ListType.extend()
L.extend(iterable) -- extend list by appending elements from the iterable
ListType.index()
L.index(value, [start, [stop]]) -> integer -- return first index of value
ListType.insert()
L.insert(index, object) -- insert object before index
ListType.pop()
L.pop([index]) -> item -- remove and return item at index (default last)
ListType.remove()
L.remove(value) -- remove first occurrence of value
ListType.reverse()
L.reverse() -- reverse *IN PLACE*
ListType.sort()
L.sort(cmpfunc=None) -- stable sort *IN PLACE*; cmpfunc(x, y) -> -1, 0, 1
Class: LongType
long(x[, base]) -> integer
Convert a string or number to a long integer, if possible. A floating
point argument will be truncated towards zero (this does not include a
string representation of a floating point number!) When converting a
string, use the optional base. It is an error to supply a base when
converting a non-string.
Class: StringType
str(object) -> string
Return a nice string representation of the object.
If the argument is a string, the return value is the same object.
Methods for class StringType
StringType.capitalize()
S.capitalize() -> string
Return a copy of the string S with only its first character
capitalized.
StringType.center()
S.center(width) -> string
Return S centered in a string of length width. Padding is done
using spaces.
StringType.count()
S.count(sub[, start[, end]]) -> int
Return the number of occurrences of substring sub in string
S[start:end]. Optional arguments start and end are
interpreted as in slice notation.
StringType.decode()
S.decode([encoding[,errors]]) -> object
Decodes S using the codec registered for encoding. encoding defaults
to the default encoding. errors may be given to set a different error
handling scheme. Default is 'strict' meaning that encoding errors raise
a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'
as well as any other name registerd with codecs.register_error that is
able to handle UnicodeDecodeErrors.
StringType.encode()
S.encode([encoding[,errors]]) -> object
Encodes S using the codec registered for encoding. encoding defaults
to the default encoding. errors may be given to set a different error
handling scheme. Default is 'strict' meaning that encoding errors raise
a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
'xmlcharrefreplace' as well as any other name registered with
codecs.register_error that is able to handle UnicodeEncodeErrors.
StringType.endswith()
S.endswith(suffix[, start[, end]]) -> bool
Return True if S ends with the specified suffix, False otherwise.
With optional start, test S beginning at that position.
With optional end, stop comparing S at that position.
StringType.expandtabs()
S.expandtabs([tabsize]) -> string
Return a copy of S where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
StringType.find()
S.find(sub [,start [,end]]) -> int
Return the lowest index in S where substring sub is found,
such that sub is contained within s[start,end]. Optional
arguments start and end are interpreted as in slice notation.
Return -1 on failure.
StringType.index()
S.index(sub [,start [,end]]) -> int
Like S.find() but raise ValueError when the substring is not found.
StringType.isalnum()
S.isalnum() -> bool
Return True if all characters in S are alphanumeric
and there is at least one character in S, False otherwise.
StringType.isalpha()
S.isalpha() -> bool
Return True if all characters in S are alphabetic
and there is at least one character in S, False otherwise.
StringType.isdigit()
S.isdigit() -> bool
Return True if there are only digit characters in S,
False otherwise.
StringType.islower()
S.islower() -> bool
Return True if all cased characters in S are lowercase and there is
at least one cased character in S, False otherwise.
StringType.isspace()
S.isspace() -> bool
Return True if there are only whitespace characters in S,
False otherwise.
StringType.istitle()
S.istitle() -> bool
Return True if S is a titlecased string, i.e. uppercase characters
may only follow uncased characters and lowercase characters only cased
ones. Return False otherwise.
StringType.isupper()
S.isupper() -> bool
Return True if all cased characters in S are uppercase and there is
at least one cased character in S, False otherwise.
StringType.join()
S.join(sequence) -> string
Return a string which is the concatenation of the strings in the
sequence. The separator between elements is S.
StringType.ljust()
S.ljust(width) -> string
Return S left justified in a string of length width. Padding is
done using spaces.
StringType.lower()
S.lower() -> string
Return a copy of the string S converted to lowercase.
StringType.lstrip()
S.lstrip([chars]) -> string or unicode
Return a copy of the string S with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
If chars is unicode, S will be converted to unicode before stripping
StringType.replace()
S.replace (old, new[, maxsplit]) -> string
Return a copy of string S with all occurrences of substring
old replaced by new. If the optional argument maxsplit is
given, only the first maxsplit occurrences are replaced.
StringType.rfind()
S.rfind(sub [,start [,end]]) -> int
Return the highest index in S where substring sub is found,
such that sub is contained within s[start,end]. Optional
arguments start and end are interpreted as in slice notation.
Return -1 on failure.
StringType.rindex()
S.rindex(sub [,start [,end]]) -> int
Like S.rfind() but raise ValueError when the substring is not found.
StringType.rjust()
S.rjust(width) -> string
Return S right justified in a string of length width. Padding is
done using spaces.
StringType.rstrip()
S.rstrip([chars]) -> string or unicode
Return a copy of the string S with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
If chars is unicode, S will be converted to unicode before stripping
StringType.split()
S.split([sep [,maxsplit]]) -> list of strings
Return a list of the words in the string S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator.
StringType.splitlines()
S.splitlines([keepends]) -> list of strings
Return a list of the lines in S, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends
is given and true.
StringType.startswith()
S.startswith(prefix[, start[, end]]) -> bool
Return True if S starts with the specified prefix, False otherwise.
With optional start, test S beginning at that position.
With optional end, stop comparing S at that position.
StringType.strip()
S.strip([chars]) -> string or unicode
Return a copy of the string S with leading and trailing
whitespace removed.
If chars is given and not None, remove characters in chars instead.
If chars is unicode, S will be converted to unicode before stripping
StringType.swapcase()
S.swapcase() -> string
Return a copy of the string S with uppercase characters
converted to lowercase and vice versa.
StringType.title()
S.title() -> string
Return a titlecased version of S, i.e. words start with uppercase
characters, all remaining cased characters have lowercase.
StringType.translate()
S.translate(table [,deletechars]) -> string
Return a copy of the string S, where all characters occurring
in the optional argument deletechars are removed, and the
remaining characters have been mapped through the given
translation table, which must be a string of length 256.
StringType.upper()
S.upper() -> string
Return a copy of the string S converted to uppercase.
StringType.zfill()
S.zfill(width) -> string
Pad a numeric string S with zeros on the left, to fill a field
of the specified width. The string S is never truncated.
Class: TupleType
tuple() -> an empty tuple
tuple(sequence) -> tuple initialized from sequence's items
If the argument is a tuple, the return value is the same object.
Class: blowfish
class for Blowfish stream encryption
Constructor Arguments:
- key - string containing encryption key, default None
- iv - 8-byte string for initial value (for chaining), default None
Methods for class blowfish
blowfish.decrypt()
decrypt - decrypt a block of data
Arguments:
- inbuf - ciphertext to be decrypted, as a string
Returns:
- Decrypted plaintext, as a string
blowfish.encrypt()
encrypt - encrypt a block of data
Arguments:
- inbuf - plaintext to be encrypted, as a string
Returns:
- Encrypted ciphertext, as a string
blowfish.setIV()
setIV - sets the cipher chaining initial value
Arguments:
- iv - 8-byte initial value, as a python string
Returns:
blowfish.setKey()
setKey
Sets the session key for the Blowfish cipher object.
Arguments:
- key - blowfish encryption key, as a string. For acceptable
security, this should be at least 16 characters
- iv - cipher initial value, as used in the chaining feedback.
Not essential, default nothing
Class: dh
class for Diffie-Hellman secure session key exchange
Constructor arguments:
Methods for class dh
dh.exportParms()
exportParms
Returns the DH key generation parameters required for a peer to generate pub keys
Arguments:
Returns:
- tuple - (generator, modulus)
dh.genParms()
generateParms
Generate random modulus for DH key generation
Arguments:
- prime_len - length of modulus (n) in bits, default 1024
- generator - g, as in pub = g^x mod n. Default 5
- myCallback - a python func for status callbacks. Must accept 2 args,
'type' and 'num'. 'type' is a number from 0 to 3. Default is no callback
Returns:
dh.genPubKey()
genPubKey
Generates a public key from generated (or imported) parameters
Arguments:
Returns:
- public key, as a long int
dh.genSessKey()
genSessKey
Calculates and returns the session key.
Arguments:
- peerKey - peer's public key, as returned from genPubKey
Returns:
dh.importParms()
importParms
Imports DH key generation parameters into this DH object.
Arguments - choice of:
- tuple - (generator, modulus)
OR:
-
- generator
- modulus (as separate arguments)
Returns:
dh.privKey()
privKey
Returns the private key as a long int
Class: dsa
For DSA signature ciphers
Methods for class dsa
dsa.generateKey()
Given that generateParameters has already been called,
generates the private/public keys
dsa.generateParameters()
Generate a set of DSA parameters, as with
DSA_generate_parameters()
Arguments:
- seed - a string to use for seeding the PRNG, optional
- func - a callback func which is periodically invoked to
report generation progress, optional
dsa.importPrivKey()
Imports public key parameters
params is a tuple (p, q, g, y, x)
dsa.importPubKey()
Imports public key parameters
params is a tuple (p, q, g, y)
dsa.privKey()
Returns the private key for this object.
Arguments:
- None
Returns:
- Private key, as a tuple (p, q, g, y, x) (refer: Applied Cryptography)
dsa.pubKey()
Returns the public key for this object.
Arguments:
- None
Returns:
- Public key, as a tuple (p, q, g, y) (refer: Applied Cryptography)
dsa.sign()
Returns a signature of string 'raw'
dsa.signSha()
Convenience method which sha1-hashes the string,
then signs it
dsa.verify()
Attempts to validate signature 'sig' against string 'raw',
returning True if sig is valid, or False if not
dsa.verifySha()
Convenience method which sha1-hashes the string,
then verifies it
Class: key
key - simple crypto API object.
This may well be the only crypto class for Python that you'll ever need.
Think of this class, and the ezPyCrypto module, as 'cryptography for
the rest of us'.
Designed to strike the optimal balance between ease of use, features
and performance.
Basic High-level methods:
- encString - encrypt a string
- decString - decrypt a string
- encStringToAscii - encrypt a string to a printable, mailable format
- decStringFromAscii - decrypt an ascii-format encrypted string
- signString - produce ascii-format signature of a string
- verifyString - verify a string against a signature
- importKey - import public key (and possibly private key too)
- exportKey - export public key only, as printable mailable string
- exportKeyPrivate - same, but export private key as well
- makeNewKeys - generate a new, random private/public key pair
Middle-level (stream-oriented) methods:
- encStart - start a stream encryption session
- encNext - encrypt another piece of data
- encEnd} - finalise stream encryption session
- decStart} - start a stream decryption session
- decNext} - decrypt the next piece of available data
- decEnd} - finalise stream decryption session
Low-level methods:
Methods for class key
key.decEnd()
Ends a stream decryption session.
key.decNext()
Decrypt the next piece of incoming stream data.
Arguments:
- chunk - some more of the encrypted stream
Returns (depending on state)
- '' - no more decrypted data available just yet, OR
- data - the next available piece of decrypted data, OR
- None - session is complete - no more data available
key.decStart()
Start a stream decryption session.
Call this method first, then feed in pieces of stream data into decNext until
there's no more data to decrypt
No arguments, nothing returned
key.decString()
Decrypts a previously encrypted string.
Arguments:
- enc - string, previously encrypted in binary mode with encString
Returns:
- dec - raw decrypted string
key.decStringFromAscii()
Decrypts a previously encrypted string in ASCII (base64)
format, as created by encryptAscii()
Arguments:
- encascii-encrypted string, as previously encrypted with
encStringToAscii()
Returns:
May generate an exception if the public key of the encrypted string
doesn't match the public/private keypair in this key object.
To work around this problem, either instantiate a key object with
the saved keypair, or use the importKey() function.
Exception will also occur if this object is not holding a private key
(which can happen if you import a key which was previously exported
via exportKey(). If you get this problem, use exportKeyPrivate() instead
to export your keypair.
key.decStringSess()
Decrypts a string against the session cipher,
with none of the high=level packaging
key.encEnd()
Called to terminate a stream session.
Encrypts any remaining data in buffer.
Kinda obsolete now that we're using stream ciphers with full
stream chaining mode.
Arguments:
Returns:
key.encNext()
Encrypt the next piece of data in a stream.
Arguments:
- raw - raw piece of data to encrypt
Returns - one of:
- '' - not enough data to encrypt yet - stored for later, OR
- encdata - string of encrypted data
key.encStart()
Starts a stream encryption session
Sets up internal buffers for accepting ad-hoc data.
No arguments needed, nothing returned.
key.encString()
Encrypt a string of data
High-level func. encrypts an entire string of data, returning the encrypted
string as binary.
Arguments:
Returns:
- encrypted string as binary
Note - the encrypted string can be stored in files, but I'd suggest
not emailing them - use L{encStringToAscii} instead. The sole advantage
of this method is that it produces more compact data, and works a bit faster.
key.encStringSess()
Encrypts a string against the session cipher,
with none of the high=level packaging
key.encStringToAscii()
Encrypts a string of data to printable ASCII format
Use this method instead of L{encString}, unless size and speed are
major issues.
This method returns encrypted data in bracketed base64 format,
safe for sending in email.
Arguments:
Returns:
- enc - encrypted string, text-wrapped and Base-64 encoded, safe for
mailing.
There's an overhead with base64-encoding. It costs size, bandwidth and
speed. Unless you need ascii-safety, use encString() instead.
key.exportKey()
Exports the public key as a printable string.
Exported keys can be imported elsewhere into MyCipher instances
with the importKey method.
Note that this object contains only the public key. If you want to
export the private key as well, call exportKeyPrivate instaead.
Note also that the exported string is Base64-encoded, and safe for sending
in email.
Arguments:
Returns:
- base64-encoded string containing an importable key
key.exportKeyPrivate()
Exports public/private key pair as a printable string.
This string is a binary string consisting of a pickled key object,
that can be imported elsewhere into key instances
with the importKey method.
Note that this object contains the public AND PRIVATE keys.
Don't EVER email any keys you export with this function (unless you
know what you're doing, and you encrypt the exported keys against
another key). When in doubt, use L{exportKey} instead.
Keep your private keys safe at all times. You have been warned.
Note also that the exported string is Base64-encoded, and safe for sending
in email.
Arguments:
Keywords:
- passphrase - default (None) to using existing passphrase.
Set to '' to export without passphrase (if this is really what you want to do!)
Returns:
- A base64-encoded string containing an importable key, or None if there is no
private key available.
key.genSessKey()
Resets block cipher to use random session key and IV
key.getSessIV()
Returns the starting IV for current session cipher
key.getSessKey()
Returns the current cipher's session key
key.hasPrivateKey()
Returns 1 if this key object has a private key, 0 if not
key.importKey()
Imports a public key or private/public key pair.
(as previously exported from this object
with the exportKey or exportKeyPrivate methods.
Arguments:
- keystring - a string previously imported with
exportKey or exportKeyPrivate
Keywords:
- passphrase - string (default '', meaning 'try to import without passphrase')
Returns:
- True if import successful, False if failed
-
You don't have to call this if you instantiate your key object
in 'import' mode - ie, by calling it with a previously exported key.
Note - you shouldn't give a 'passphrase' when importing a public key.
key.makeNewKeys()
Creates a new keypair in cipher object, and a new session key
Arguments:
- keysize (default 512), advise at least 1536
Returns:
- None
Keywords:
- passphrase - used to secure exported private key - default '' (no passphrase)
- e - e value, in case of RSA
Keypair gets stored within the key object. Refer exportKey()
exportKeyPrivate() and importKey()
Generally no need to call this yourself, since the constructor
calls this in cases where you aren't instantiating with an
importable key.
key.setSessKey()
Resets block cipher to use given session key and IV
key.signString()
Sign a string using private key
Arguments:
- raw - string to be signed
- wrap - wrap in email-friendly ASCII, default True
Returns:
- wrapped, base-64 encoded string of signature
Note - private key must already be present in the key object.
Call importKey() for the right private key first if needed.
key.test()
Encrypts, then decrypts a string. What you get back should
be the same as what you put in.
This is totally useless - it just gives a way to test if this API
is doing what it should.
key.testAscii()
Encrypts, then decrypts a string. What you get back should
be the same as what you put in.
This is totally useless - it just gives a way to test if this API
is doing what it should.
key.verifyString()
Verifies a string against a signature.
Object must first have the correct public key loaded. (see
importKey. An exception will occur if this is not the case.
Arguments:
- raw - string to be verified
- signature - as produced when key is signed with signString
- wrap - take signature as email-friendly wrapped (default True)
Returns:
- True if signature is authentic, or False if not
key._calcPubBlkSize()
Determine size of public key
key._calcSesBlkSize()
Determine size of session blocks
key._decRawPub()
Decrypt a public-key encrypted block, and return the decrypted string
Arguments:
- enc - the encrypted string, in the format as
created by _encRawPub()
Returns:
Note- The ciphertext should be prefixed by 2
length bytes, LSB first, as created by
_encRawPub
key._encRawPub()
Encrypt a small raw string using the public key
algorithm. Input must not exceed the allowable
block size.
Arguments:
- raw - small raw bit of string to encrypt
Returns:
- binary representation of encrypted chunk, or
None if verify failed
Note - returned block is prefixed by 2 length bytes, LSB first
key._genNewSessKey()
Generate a new random session key
key._initBlkCipher()
Create a new block cipher object, set up with a new session key
and IV
key._random()
Generate an n-byte random number and return it as a string
key._rawPrivKey()
Returns a binary-encoded string of private key, or None if there is no private key
key._rawPubKey()
Returns a binary-encoded string of public key
key._setNewSessKey()
Sets the session key to specific values
key._testPubKey()
Checks if binary-encoded key matches this object's pubkey
key._unwrap()
Unwraps a previously _wrap()'ed message.
key._wrap()
Encodes message as base64 and wraps with /
Args:
- type - string to use in header/footer - eg 'Key', 'Message'
- msg - binary string to wrap
Class: rsa
class for RSA public-key encryption
Constructor Arguments:
Methods for class rsa
rsa.decrypt()
decrypt a previously encrypted block
Arguments:
- cipher - ciphertext to be decrypted, as a string
Returns:
- plaintext - decrypted asa python string
rsa.encrypt()
Encrypts a block of data.
Arguments:
- plain - plaintext to be encrypted, as a string
Returns:
- ciphertext - encrypted data, as a string
Note: This method has a strict limit as to the size of the block which can
be encrypted. To determine the limit, call the maxSize method.
rsa.generateKey()
Generate a fresh RSA keypair
Arguments:
- bits - length of required key in bits, >=1024 recommended, default 1024
Keywords:
- e - exponent for key generation, default 5
- myCallback - a Python callback function which accepts
2 arguments - level and num. Default None
rsa.hasPrivateKey()
Returns True if private key is present in this key object (and therefore the
key object is capable of decryption), or False if not.
rsa.importPrivKey()
importPubKey - import private key parameters
Arguments:
- (e, n, d), as a tuple (as returned by privKey())
rsa.importPubKey()
Import someone else's public key
Arguments:
- (e, n), a tuple (as returned by pubKey()),
rsa.maxSize()
Returns the maximum allowable size of plaintext strings which can
be encrypted
rsa.privKey()
Returns the public key for this object.
Arguments:
Returns:
- Public and Private key, as a tuple (e, n, d) (refer: Applied Cryptography)
rsa.pubKey()
Returns the public key for this object.
Arguments:
- None
Returns:
- Public key, as a tuple (e, n) (refer: Applied Cryptography)
rsa.rawprimes()
Returns the p and q for this RSA key.
Arguments:
Returns:
- p and q as a tuple (refer: Applied Cryptography)
rsa.sign()
Signs an MD5 message digest
Arguments:
- digest - MD5 digest of data, as a string
Returns:
- signature, as a MIME-friendly, base64-encoded string
rsa.verify()
Verify a digest against a signature
Arguments:
- digest - digest against which signature is to be checked.
- signature - signature as returned from the sign() method
Returns:
- True if signature is valid, or False if not.
Note:
- To pass as valid, the key object must contain the same public key as was used
in creating the original signature
Global Functions:
GCD()
GCD(a:long, b:long): long
Return the GCD of a and b.
StringIO()
StringIO([s]) -- Return a StringIO-like stream for reading or writing
bdecode()
None
bdecode_rec()
None
bencode()
None
bencode_rec()
None
bytes_to_long()
bytes_to_long(string) : long
Convert a byte string to a long integer.
string is big-endian byte order
This is (essentially) the inverse of long_to_bytes().
decode_dict()
None
decode_int()
None
decode_list()
None
decode_string()
None
genprime()
Generate a secure (Sophie-Germain) prime number
Arguments:
- bits - number of bits length, default 256
- callback - a function which accepts 2 arguents - level, num - for giving
user some feedback of progress
genrandom()
Generates an n-bit quality random number
inverse()
inverse(u:long, u:long):long
Return the inverse of u mod v.
long_to_bytes()
convert a number back to a string
string is big-endian byte order
randomseed()
randomseed - feed entropy to the random number generator
Allows client code to pass entropy to OpenSSL's pseudo-random
number generation.
You must call this function before doing anything with this module.
If you don't, you'll be totally susceptible to random number analysis
attacks, and your security could be dead in the water. You have been warned!
Arguments:
- entropy - a plain string of data to be fed in as entropy.
You can pass anything you like here - sampled mouse movements,
keystrokes etc.
Returns:
rndfunc()
None
size()
size(N:long) : int
Returns the size of the number N in bits.
_die()
None
_exctest()
Tests exception handling in pyrex"
Exceptions:
CryptoCannotDecrypt
Cannot decrypt - private key not present
CryptoInvalidCiphertext
Ciphertext was not produced with SSLCrypto
CryptoInvalidElGamalK
Invalid k parameter for ElGamal operation
CryptoInvalidSignature
Signature text was not produced with SSLCrypto
CryptoKeyError
Attempt to import invalid key
CryptoNoPrivateKey
Key object has no private key