How to fix "unable to write 'random state' " in openssl

WindowsOpenssl

Windows Problem Overview


While generating the private key using this command

genrsa -out my-prvkey.pem 1024
        

It throws the error like below

> Loadind 'screen' into random state -done Generating RSA private > key,1024 bit long modulus > .........................................+++++++ > ...........................+++++++++ unable to write 'random state' e > is 65537 (0*10001)

This makes any problem while creating a public certificate. I'm running this command in windows. Can anyone help me for the fix?

Windows Solutions


Solution 1 - Windows

The quickest solution is: set environment variable RANDFILE to path where the 'random state' file can be written (of course check the file access permissions), eg. in your command prompt:

set RANDFILE=C:\MyDir\.rnd
openssl genrsa -out my-prvkey.pem 1024

More explanations: OpenSSL on Windows tries to save the 'random state' file in the following order:

  1. Path taken from RANDFILE environment variable
  2. If HOME environment variable is set then : ${HOME}\.rnd
  3. C:\.rnd

I'm pretty sure that in your case it ends up trying to save it in C:\.rnd (and it fails because lack of sufficient access rights). Unfortunately OpenSSL does not print the path that is actually tries to use in any error messages.

Solution 2 - Windows

It may also be that you need to run the console as an administrator. On windows 7, hold ctrl+shift when you launch the console window.

Solution 3 - Windows

just enter this line in the command line :

set RANDFILE=.rnd

Solution 4 - Windows

Or this in windows powershell

$env:RANDFILE=".rnd"

Solution 5 - Windows

I did not find where the .rnd file is so I ran the cmd as administrator and it worked like a charm.

Solution 6 - Windows

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionarokView Question on Stackoverflow
Solution 1 - WindowssirgeorgeView Answer on Stackoverflow
Solution 2 - WindowsalileView Answer on Stackoverflow
Solution 3 - WindowseliprodigyView Answer on Stackoverflow
Solution 4 - WindowskonzoView Answer on Stackoverflow
Solution 5 - WindowsDoan VuView Answer on Stackoverflow
Solution 6 - WindowsRohit BorudeView Answer on Stackoverflow