List of usage examples for java.util Random nextBytes
public void nextBytes(byte[] bytes)
From source file:de.mpg.escidoc.services.aa.TanStore.java
/** * Generate a random transaction number. * /*from w w w . j av a 2 s . c o m*/ * @param id The session id. * @return a random transaction number */ public static String createTan(String id) { Random random = new Random(new Date().getTime()); byte[] tanBytes = new byte[16]; random.nextBytes(tanBytes); return new String(Base64.encodeBase64(tanBytes)); }
From source file:org.apache.hadoop.hdfs.protocol.RandomObjectsGenerators.java
static byte[] rndByteArr(Random rnd, int count) { byte[] bytes = new byte[count]; rnd.nextBytes(bytes); return bytes; }
From source file:org.jahia.utils.zip.DirectoryZipInputStreamTest.java
@BeforeClass public static void oneTimeSetUp() { tempDirectory = FileUtils.getTempDirectory(); outputDirectory = new File(tempDirectory, "dirzip-dest-" + System.currentTimeMillis()); outputDirectory.mkdirs();//from w w w . j a v a 2 s . c o m Random random = new Random(); random.nextBytes(randomBuffer); }
From source file:org.apache.hadoop.hbase.util.test.LoadTestKVGenerator.java
/** * Generates random bytes of the given size for the given row and column * qualifier. The random seed is fully determined by these parameters. *///w ww .j a v a 2 s .c o m private static byte[] getValueForRowColumn(int dataSize, byte[]... seedStrings) { long seed = dataSize; for (byte[] str : seedStrings) { seed += Bytes.toString(str).hashCode(); } Random seededRandom = new Random(seed); byte[] randomBytes = new byte[dataSize]; seededRandom.nextBytes(randomBytes); return randomBytes; }
From source file:org.apache.hadoop.fs.TestListFiles.java
private static void writeFile(FileSystem fileSys, Path name, int fileSize) throws IOException { // Create and write a file that contains three blocks of data FSDataOutputStream stm = fileSys.create(name); byte[] buffer = new byte[fileSize]; Random rand = new Random(seed); rand.nextBytes(buffer); stm.write(buffer);//from w w w . j a va 2s . c om stm.close(); }
From source file:org.apache.hadoop.hbase.util.LoadTestKVGenerator.java
/** * Generates random bytes of the given size for the given row and column * qualifier. The random seed is fully determined by these parameters. *//* ww w . j a v a2 s .c o m*/ private static byte[] getValueForRowColumn(int dataSize, byte[]... seedStrings) { long seed = dataSize; for (byte[] str : seedStrings) { final String bytesString = Bytes.toString(str); if (bytesString != null) { seed += bytesString.hashCode(); } } Random seededRandom = new Random(seed); byte[] randomBytes = new byte[dataSize]; seededRandom.nextBytes(randomBytes); return randomBytes; }
From source file:com.g414.dgen.field.Fields.java
/** * returns some random Hex bytes : note, length is of "original" binary * bytes//from w ww . java 2 s. c o m */ public static Field<String> getRandomHexBytesField(final String name, final int length) { return new Field<String>() { @Override public String getName() { return name; } @Override public String getValue(String entityId, Map<String, Object> entitySoFar, Random random) { byte[] next = new byte[length]; random.nextBytes(next); return Hex.encodeHexString(next); } }; }
From source file:com.g414.dgen.field.Fields.java
/** returns some random bytes */ public static Field<byte[]> getRandomBinaryField(final String name, final int length) { return new Field<byte[]>() { @Override/*w w w.ja v a 2 s . c om*/ public String getName() { return name; } @Override public byte[] getValue(String entityId, Map<String, Object> entitySoFar, Random random) { byte[] next = new byte[length]; random.nextBytes(next); return next; } }; }
From source file:com.asquareb.kaaval.MachineKey.java
/** * Method to encrypt a string. Accepts the string to be encrypted and the * name of the file to store the key vale which can be used for decryption *//*from www.j av a 2 s .com*/ public static String encrypt(String property, String app) throws IOException, KaavalException { InetAddress ip = null; String ipAddress = null; ObjectOutputStream os = null; NetworkInterface macAddress = null; byte[] macId = null; Cipher pbeCipher = null; Random rand = new Random(); rand.nextBytes(salt); try { SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); SecretKey key = keyFactory.generateSecret(new PBEKeySpec(password)); ip = InetAddress.getLocalHost(); ipAddress = ip.getHostAddress(); macAddress = NetworkInterface.getByInetAddress(ip); macId = macAddress.getHardwareAddress(); MachineKey mKey = new MachineKey(); mKey.api = ipAddress; mKey.macad = new String(macId); mKey.yek = key; mKey.tlas = salt; mKey.eti = rand.nextInt(1000); os = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(app))); os.writeObject(mKey); os.close(); pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(salt, mKey.eti)); return base64Encode(pbeCipher.doFinal(property.getBytes())); } catch (IOException e) { throw new KaavalException(1, "Error in key file during encryption", e); } catch (Exception e) { throw new KaavalException(2, "Errors during encryption", e); } finally { if (os != null) os.close(); } }
From source file:org.apache.kylin.storage.hbase.util.HbaseStreamingInput.java
private static byte[] randomBytes(int lenth) { byte[] bytes = new byte[lenth]; Random rand = new Random(); rand.nextBytes(bytes); return bytes; }