Last active
August 29, 2015 14:14
-
-
Save westonal/14c52b2a41ac41119dba to your computer and use it in GitHub Desktop.
Salt shaker - Salt generator using secure random
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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