Package java.security

Examples of java.security.SecureRandom.nextInt()


        if (max <= 0) {
            // the range is too wide to fit in a positive int (larger than 2^31); as it covers
            // more than half the integer range, we use directly a simple rejection method
            final SecureRandom rng = getSecRan();
            while (true) {
                final int r = rng.nextInt();
                if (r >= lower && r <= upper) {
                    return r;
                }
            }
        } else {
View Full Code Here


        byte[] expected = testString.getBytes(CharsetUtil.UTF_8.name());
        InputStream in = new StringInputStream(testString, CharsetUtil.UTF_8);
        byte[] buffer = new byte[128];
        int offset = 0;
        while (true) {
            int bufferOffset = rnd.nextInt(64);
            int bufferLength = rnd.nextInt(64);
            int read = in.read(buffer, bufferOffset, bufferLength);
            if (read == -1) {
                assertEquals(offset, expected.length);
                break;
View Full Code Here

        InputStream in = new StringInputStream(testString, CharsetUtil.UTF_8);
        byte[] buffer = new byte[128];
        int offset = 0;
        while (true) {
            int bufferOffset = rnd.nextInt(64);
            int bufferLength = rnd.nextInt(64);
            int read = in.read(buffer, bufferOffset, bufferLength);
            if (read == -1) {
                assertEquals(offset, expected.length);
                break;
            } else {
View Full Code Here

        }
        else if ( HASH_METHOD_CRYPT.equals( hashMethod ) )
        {
            this.salt = new byte[2];
            SecureRandom sr = new SecureRandom();
            int i1 = sr.nextInt( 64 );
            int i2 = sr.nextInt( 64 );
            this.salt[0] = ( byte ) ( i1 < 12 ? ( i1 + '.' ) : i1 < 38 ? ( i1 + 'A' - 12 ) : ( i1 + 'a' - 38 ) );
            this.salt[1] = ( byte ) ( i2 < 12 ? ( i2 + '.' ) : i2 < 38 ? ( i2 + 'A' - 12 ) : ( i2 + 'a' - 38 ) );
        }
        else
View Full Code Here

        else if ( HASH_METHOD_CRYPT.equals( hashMethod ) )
        {
            this.salt = new byte[2];
            SecureRandom sr = new SecureRandom();
            int i1 = sr.nextInt( 64 );
            int i2 = sr.nextInt( 64 );
            this.salt[0] = ( byte ) ( i1 < 12 ? ( i1 + '.' ) : i1 < 38 ? ( i1 + 'A' - 12 ) : ( i1 + 'a' - 38 ) );
            this.salt[1] = ( byte ) ( i2 < 12 ? ( i2 + '.' ) : i2 < 38 ? ( i2 + 'A' - 12 ) : ( i2 + 'a' - 38 ) );
        }
        else
        {
View Full Code Here

  String password = "";
  char next = 0;
  int range = 10;

  for (int i = 0; i < PASSWORD_LENGTH; i++) {
      switch (rnd.nextInt(3)) {
      case 0: {next = '0'; range = 10;} break;
      case 1: {next = 'a'; range = 26;} break;
      case 2: {next = 'A'; range = 26;} break;
      }
      password += (char) ((rnd.nextInt(range)) + next);
View Full Code Here

      switch (rnd.nextInt(3)) {
      case 0: {next = '0'; range = 10;} break;
      case 1: {next = 'a'; range = 26;} break;
      case 2: {next = 'A'; range = 26;} break;
      }
      password += (char) ((rnd.nextInt(range)) + next);
  }
  // TODO remove output
  System.out.println(password);
  return password;
    }
View Full Code Here

        {
          String key = "abc" + (rnd.nextDouble() * iterations);
          keys.add(key);
          map.put(key, new BufferedWebResponse(null));

          String key2 = keys.get(rnd.nextInt(keys.size() - 1));
          map.remove(key2);
        }
        endLatch.countDown();
      }
    };
View Full Code Here

            //This is a lengthy operation, to be done only upon
            //initialization of the application
            SecureRandom prng = SecureRandom.getInstance("SHA1PRNG");

            //generate a random number
            String randomNum = Integer.toString(prng.nextInt());

            //get its digest
            MessageDigest sha = MessageDigest.getInstance("SHA-1");
            byte[] result = sha.digest(randomNum.getBytes());
            return hexEncode(result);
View Full Code Here

     * @return
     */
    public static String genericID() {
        try {
            SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
            int i = random.nextInt(Integer.MAX_VALUE);
            return String.valueOf(i);
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.