Sample code for 30+ languages & platforms
Java

Generate Salt in Hex or Base64 Format

See more Encryption Examples

Demonstrates how to generate a cryptographic salt value and get the result as hex or base64.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    // In cryptography, a salt is random data that is used as an additional input to a one-way function that "hashes" data, a password or passphrase.

    // Let's say we want to generate a 16-byte salt value..
    CkPrng prng = new CkPrng();

    String saltHex = prng.genRandom(16,"hex");
    System.out.println("16-byte salt as hex: " + saltHex);

    String saltBase64 = prng.genRandom(16,"base64");
    System.out.println("16-byte salt as base64: " + saltBase64);
  }
}