I try to use PyCryptodome for producing RSA key with a call to os.urandom to first get som random numbers. I must do some statistical testing and processing on the random data before i generate the RSA keys. I can use a file object to for loading the random numbers from file. I'm really scratching my head on this one..
fx = open("rnd.dat", "rb")
key = RSA.generate(1024, fx.read)
The code below works.
key = RSA.generate(1024, v1.readstd()) #Works!
The code here doesn't .
key = RSA.generate(1024, v1.read()) #Not working....
I have included the source.
from Crypto.PublicKey import RSA # PyCryptodome
from Crypto import Random
import os
class trng:
def __init__(self, rngval):
self.rngval = rngval
def read(self):
return self.rngval
def readstd(self):
return Random.get_random_bytes
rngbuff=os.urandom(1024)
#....Here will go some processing
#..
#....end
v1 = trng(rngbuff)
key1 = RSA.generate(1024, v1.readstd()) #Works!
fx = open("rnd.dat", "rb")
key2 = RSA.generate(1024, fx.read) #Works!
key3 = RSA.generate(1024, v1.read()) #Not working....