Ensure files are closed promptly when generating a key pair

On Python's without reference counting (e.g. PyPy) the current code will keep
the file descriptors open for an arbitrary length of time, until the GC runs.

Change-Id: Idf81df95894fed1d13a68705ef490d5a29367ff1
Merge "Ensure files are closed promptly when generating a key pair"