Skip to content

Instantly share code, notes, and snippets.

@westonal
Last active August 29, 2015 14:14
Show Gist options
  • Save westonal/14c52b2a41ac41119dba to your computer and use it in GitHub Desktop.
Save westonal/14c52b2a41ac41119dba to your computer and use it in GitHub Desktop.
Salt shaker - Salt generator using secure random
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.security.SecureRandom;
public final class SaltShaker {
public static void main(String[] args) {
final byte[] data = new byte[20];
new SecureRandom().nextBytes(data);
final StringBuilder sb = new StringBuilder();
sb.append("private static final byte[] SALT = new byte[] { ");
for (int i = 0; i < data.length; i++) {
byte b = data[i];
if (i > 0)
sb.append(", ");
sb.append(b);
}
sb.append(" };");
final StringSelection stringSelection = new StringSelection(
sb.toString());
final Clipboard systemClipboard = Toolkit.getDefaultToolkit()
.getSystemClipboard();
systemClipboard.setContents(stringSelection, null);
System.out.println("New salt was copied to clipboard");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment