Here you can find the source of timestampNonce(final int length)
Parameter | Description |
---|---|
length | Positive number of bytes in nonce. |
public static byte[] timestampNonce(final int length)
//package com.java2s; /* See LICENSE for licensing and NOTICE for copyright. */ public class Main { /**/*from w w w . java 2 s. c o m*/ * Generates a nonce of the given size by repetitively concatenating system * timestamps (i.e. {@link System#nanoTime()}) up to the required size. * * @param length Positive number of bytes in nonce. * * @return Nonce bytes. */ public static byte[] timestampNonce(final int length) { if (length <= 0) { throw new IllegalArgumentException(length + " is invalid. Length must be positive."); } final byte[] nonce = new byte[length]; int count = 0; long timestamp; while (count < length) { timestamp = System.nanoTime(); for (int i = 0; i < 8 && count < length; i++) { nonce[count++] = (byte) (timestamp & 0xFF); timestamp >>= 8; } } return nonce; } }