Skip to content

Instantly share code, notes, and snippets.

@jabocg
Created April 21, 2016 22:58
Show Gist options
  • Save jabocg/4f972e6c09c6b5ca62afd379fe94b11f to your computer and use it in GitHub Desktop.
Save jabocg/4f972e6c09c6b5ca62afd379fe94b11f to your computer and use it in GitHub Desktop.
// 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