generate(bits,
randfunc=None,
progress_func=None,
e=65537)
|
|
Randomly generate a fresh, new RSA key object.
See RSAImplementation.generate.
- Parameters:
bits (int) - Key length, or size (in bits) of the RSA modulus.
It must be a multiple of 256, and no smaller than 1024.
randfunc (callable) - Random number generation function; it should accept
a single integer N and return a string of random data
N bytes long.
progress_func (callable) - Optional function that will be called with a short string
containing the key parameter currently being generated;
it's useful for interactive applications where a user is
waiting for a key to be generated.
e (int) - Public RSA exponent. It must be an odd positive integer.
It is typically a small number with very few ones in its
binary representation.
The default value 65537 (= 0b10000000000000001 ) is a safe
choice: other common values are 5, 7, 17, and 257.
- Raises:
ValueError - When bits is too little or not a multiple of 256, or when
e is not odd or smaller than 2.
Attention:
-
You should always use a cryptographically secure random number generator,
such as the one defined in the Crypto.Random module; don't just use the
current time and the random module.
-
Exponent 3 is also widely used, but it requires very special care when padding
the message.
|