Example usage for java.security SecureRandom generateSeed

List of usage examples for java.security SecureRandom generateSeed

Introduction

In this page you can find the example usage for java.security SecureRandom generateSeed.

Prototype

public byte[] generateSeed(int numBytes) 

Source Link

Document

Returns the given number of seed bytes, computed using the seed generation algorithm that this class uses to seed itself.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");

    System.out.println(Arrays.toString(sr.generateSeed(8)));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");

    int seedByteCount = 10;
    byte[] seed = sr.generateSeed(seedByteCount);
}

From source file:com.amazonaws.cognito.sync.devauth.client.AmazonCognitoSampleDeveloperAuthenticationClient.java

/**
 * Creates a 128 bit random string..//from  www.j a  v a2  s.co  m
 */
public static String generateRandomString() {
    SecureRandom random = new SecureRandom();
    byte[] randomBytes = random.generateSeed(16);
    String randomString = new String(Hex.encodeHex(randomBytes));
    return randomString;
}

From source file:com.axelor.apps.account.ebics.certificate.KeyUtil.java

/**
 * Generates a random password//from  w  w w.jav  a2  s  . c  o m
 *
 * @return the password
 */
public static String generatePassword() {
    SecureRandom random;

    try {
        random = SecureRandom.getInstance("SHA1PRNG");
        String pwd = Base64.encodeBase64String(random.generateSeed(5));

        return pwd.substring(0, pwd.length() - 2);
    } catch (NoSuchAlgorithmException e) {
        return "changeit";
    }
}

From source file:org.linagora.linshare.core.utils.HashUtils.java

/**
 * generate salt (32 bits/4 octets)//from   w ww  .j  a  va2  s. c om
 * @return
 */
public static byte[] getSalt() {
    // Get 32 random bits
    byte[] mybytes;
    try {
        // Create a secure random number generator
        SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");

        // Create secure number generator with seed
        int seedByteCount = 10;
        byte[] seed = sr.generateSeed(seedByteCount);

        sr = SecureRandom.getInstance("SHA1PRNG");
        sr.setSeed(seed);

        mybytes = new byte[32 / 8];
        sr.nextBytes(mybytes);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
    return mybytes;
}

From source file:Main.java

public static String generateNonce() {
    try {/* ww w. j  ava  2  s .  c om*/
        // Create a secure random number generator
        SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");

        // Get 1024 random bits
        byte[] bytes = new byte[1024 / 8];
        sr.nextBytes(bytes);

        // Create two secure number generators with the same seed
        int seedByteCount = 10;
        byte[] seed = sr.generateSeed(seedByteCount);

        sr = SecureRandom.getInstance("SHA1PRNG");
        sr.setSeed(seed);
        SecureRandom sr2 = SecureRandom.getInstance("SHA1PRNG");
        sr2.setSeed(seed);

        String nonce = Long.toHexString(sr2.nextLong());
        nonce = nonce.substring(0, 7);

        return nonce;

    } catch (NoSuchAlgorithmException e) {
    }
    return null;
}

From source file:com.aimluck.eip.util.ALCommonUtils.java

/**
 * ID??SecureRandom????//w w w .j a  va  2s  .  c  o  m
 * 
 * @return random ID??SecureRandom
 */
public static SecureRandom getSecureRandom() {
    SecureRandom random = null;
    try {
        random = SecureRandom.getInstance(DEF_RANDOM_ALGORITHM);
        byte seed[] = random.generateSeed(DEF_RANDOM_LENGTH);
        random.setSeed(seed);
    } catch (Exception e) {
        logger.error("ALCommonUtils.getSecureRandom", e);
        return null;
    }
    return random;
}

From source file:pt.aptoide.backupapps.data.webservices.ManagerUploads.java

public static String generateBoundary() {
    try {//from   ww w.  ja  v  a 2 s . co m
        // Create a secure random number generator
        SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");

        // Get 1024 random bits
        byte[] bytes = new byte[1024 / 8];
        sr.nextBytes(bytes);

        int seedByteCount = 10;
        byte[] seed = sr.generateSeed(seedByteCount);

        sr = SecureRandom.getInstance("SHA1PRNG");
        sr.setSeed(seed);

        return "***" + Long.toString(sr.nextLong()) + "***";

    } catch (NoSuchAlgorithmException e) {
    }
    return "*********";
}

From source file:com.example.ExerciseMe.tvmclient.AmazonTVMClient.java

/**
 * Creates a 128-bit random string.//w ww  .  j a v  a  2s .c  o  m
 */
public String generateRandomString() {
    SecureRandom random = new SecureRandom();
    byte[] randomBytes = random.generateSeed(16);
    return new String(Hex.encodeHex(randomBytes));
}

From source file:com.ad.mediasharing.tvmclient.AmazonTVMClient.java

/**
 * Creates a 128-bit random string./*from   w  w  w.  j  a  v a  2  s  .c  o m*/
 */
public String generateRandomString() {
    SecureRandom random = new SecureRandom();
    byte[] randomBytes = random.generateSeed(16);
    String randomString = new String(Hex.encodeHex(randomBytes));
    return randomString;
}