Search code examples
pythonpycrypto

Pycrypto - Using Crypto.Random to generate a secret key and an initialisation vector


Can Crypto.Random be used to safely generate a strong secret key and an initialisation vector?


Solution

  • According to the PyCryto docs, the answer is yes:

    from Crypto.PublicKey import RSA
    from Crypto import Random
    rng = Random.new().read
    RSAkey = RSA.generate(1024, rng)