Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to randomize RandomData #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/com/licel/jcardsim/crypto/RandomDataImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import org.bouncycastle.crypto.digests.SHA1Digest;
import org.bouncycastle.crypto.prng.DigestRandomGenerator;
import org.bouncycastle.crypto.prng.RandomGenerator;
import org.bouncycastle.util.encoders.Hex;

import java.security.SecureRandom;

/**
* Implementation <code>RandomData</code> based
Expand All @@ -34,6 +37,18 @@ public class RandomDataImpl extends RandomData {
public RandomDataImpl(byte algorithm) {
this.algorithm = algorithm;
this.engine = new DigestRandomGenerator(new SHA1Digest());

final String randomSeed = System.getProperty("com.licel.jcardsim.randomdata.seed");
final String doSecureRandom = System.getProperty("com.licel.jcardsim.randomdata.secure", "0");
if (randomSeed != null){
this.engine.addSeedMaterial(Hex.decode(randomSeed));
}
else if ("1".equals(doSecureRandom)){
byte[] seed = new byte[32];
SecureRandom randomGenerator = new SecureRandom();
randomGenerator.nextBytes(seed);
this.engine.addSeedMaterial(seed);
}
}

public void generateData(byte[] buffer, short offset, short length) throws CryptoException {
Expand Down