Created
April 21, 2016 22:58
-
-
Save jabocg/4f972e6c09c6b5ca62afd379fe94b11f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add the required amount of entropy | |
boolean entropic = false; | |
CertificationSigningRequest csr = null; | |
final FileInputStream fin = new FileInputStream("/dev/urandom"); | |
byte[] b; | |
while (!entropic) { | |
try { | |
// read in 32 bits of data from /dev/urandom | |
b = new byte[32]; | |
fin.read(b); | |
System.out.println("adding entropy to SAIFE library"); | |
// add entropy to the SAIFE library, telling it 4 out of every 8 bits | |
// are entropic enough | |
saife.AddEntropy(b, 4); | |
// attempt to generate a CSR | |
csr = saife.generateSmCsr(dn, defaultPassword); | |
entropic = true; | |
} catch (final InsufficientEntropyException e) { | |
System.out.println(e.getMessage()); | |
entropic = false; | |
} catch (final IOException e) { | |
System.out.println("Error reading in from /dev/urandom"); | |
} | |
} | |
try { | |
fin.close(); | |
} catch (final IOException e) {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment