Java Salt Value Create generateSalt(int numBytes)

Here you can find the source of generateSalt(int numBytes)

Description

generate Salt

License

Apache License

Declaration

public static byte[] generateSalt(int numBytes) 

Method Source Code

//package com.java2s;
/**/*w w  w.  j ava 2  s  . c om*/
 * Copyright (c) 2005-2012 springside.org.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */

import java.security.SecureRandom;

public class Main {
    private static SecureRandom random = new SecureRandom();

    public static byte[] generateSalt(int numBytes) {
        if (numBytes <= 0) {
            throw new IllegalArgumentException(String
                    .format("numBytes argument must be a positive integer (1 or larger)", Long.valueOf(numBytes)));
        }
        byte[] bytes = new byte[numBytes];
        random.nextBytes(bytes);
        return bytes;
    }
}

Related

  1. generateSalt(final Integer size)
  2. generateSalt(int bits)
  3. generateSalt(int byteSize)
  4. generateSalt(int length)
  5. generateSalt(int numberOfBytes)
  6. generateSaltAESPBKDF2()
  7. generateSaltedPassword(final String password, byte[] salt, int iterationsCount, String hmacName)
  8. generateSaltedSHAHash(String algorithm, String input, String salt)
  9. generateSaltOfLength(int length)