Java Salt Value Create generateSalt()

Here you can find the source of generateSalt()

Description

generate Salt

License

Apache License

Declaration

public static String generateSalt() throws NoSuchAlgorithmException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import javax.crypto.*;

import java.security.NoSuchAlgorithmException;

public class Main {
    private static final String AES = "AES";
    private static final int KEY_SIZE = 128;
    private static final int HEX = 16;
    private static final int BYTE_LEN = 2;

    public static String generateSalt() throws NoSuchAlgorithmException {
        KeyGenerator keyGenerator = KeyGenerator.getInstance(AES);
        keyGenerator.init(KEY_SIZE);/*from w w w  .j  av  a 2  s .  co  m*/
        return byteArrayToHexString(keyGenerator.generateKey().getEncoded());
    }

    private static String byteArrayToHexString(byte[] b) {
        StringBuilder sb = new StringBuilder(b.length * BYTE_LEN);
        for (byte aB : b) {
            int v = aB & 0xff;
            if (v < HEX) {
                sb.append('0');
            }
            sb.append(Integer.toHexString(v));
        }
        return sb.toString().toUpperCase();
    }
}

Related

  1. generateSalt()
  2. generateSalt()
  3. generateSalt()
  4. generateSalt()
  5. generateSalt()
  6. generateSalt()
  7. generateSalt()
  8. generateSalt()
  9. generateSalt()