List of usage examples for org.bouncycastle.crypto.prng RandomGenerator nextBytes
void nextBytes(byte[] bytes);
From source file:gnu.java.bigintcrypto.BigIntegerCrypto.java
License:Open Source License
private void init(int numBits, RandomGenerator rnd) { int highbits = numBits & 31; // minimum number of bytes to store the above number of bits int highBitByteCount = (highbits + 7) / 8; // number of bits to discard from the last byte int discardedBitCount = highbits % 8; if (discardedBitCount != 0) discardedBitCount = 8 - discardedBitCount; byte[] highBitBytes = new byte[highBitByteCount]; if (highbits > 0) { rnd.nextBytes(highBitBytes); highbits = (highBitBytes[highBitByteCount - 1] & 0xFF) >>> discardedBitCount; for (int i = highBitByteCount - 2; i >= 0; i--) highbits = (highbits << 8) | (highBitBytes[i] & 0xFF); }/* ww w .j a v a 2 s . c om*/ int nwords = numBits / 32; byte tmpBytes[] = new byte[4]; while (highbits == 0 && nwords > 0) { rnd.nextBytes(tmpBytes); highbits = (byte) tmpBytes[0]; highbits |= tmpBytes[1] << 8; highbits |= tmpBytes[2] << 16; highbits |= tmpBytes[3] << 24; --nwords; } if (nwords == 0 && highbits >= 0) { ival = highbits; } else { ival = highbits < 0 ? nwords + 2 : nwords + 1; words = new int[ival]; words[nwords] = highbits; while (--nwords >= 0) { rnd.nextBytes(tmpBytes); words[nwords] = (byte) tmpBytes[0]; words[nwords] |= tmpBytes[1] << 8; words[nwords] |= tmpBytes[2] << 16; words[nwords] |= tmpBytes[3] << 24; } } }
From source file:net.sourceforge.keepassj2me.keydb.KeydbDatabase.java
License:Open Source License
protected int getRandom() { byte[] id = new byte[4]; RandomGenerator rnd = new DigestRandomGenerator(new SHA1Digest()); rnd.addSeedMaterial(System.currentTimeMillis()); rnd.nextBytes(id); return (id[0] | (id[1] << 8) | (id[2] << 16) | (id[3] << 24)); }
From source file:net.sourceforge.keepassj2me.keydb.KeydbEntry.java
License:Open Source License
/** * Generate entry uuid/* ww w . java 2 s .co m*/ * @return uuid */ public byte[] createUUID() {//FIXME: make sure this is unique byte[] uuid = new byte[16]; RandomGenerator rnd = new DigestRandomGenerator(new SHA1Digest()); rnd.addSeedMaterial(System.currentTimeMillis()); rnd.nextBytes(uuid); return uuid; }
From source file:net.sourceforge.keepassj2me.keydb.KeydbHeader.java
License:Open Source License
/** * Reinitialize header//from w w w . j a v a 2 s . co m * @param rounds */ public void reinitialize(int rounds) { numKeyEncRounds = rounds; //SecureRandom rnd = SecureRandom.getInstance("SHA1PRNG"); //rnd.setSeed(System.currentTimeMillis()); RandomGenerator rnd = new DigestRandomGenerator(new SHA1Digest()); rnd.addSeedMaterial(System.currentTimeMillis()); rnd.nextBytes(masterSeed); rnd.nextBytes(encryptionIV); rnd.nextBytes(masterSeed2); }