Skip to content

Instantly share code, notes, and snippets.

@aphexmunky
Created October 24, 2012 09:40
Show Gist options
  • Save aphexmunky/3945152 to your computer and use it in GitHub Desktop.
Save aphexmunky/3945152 to your computer and use it in GitHub Desktop.
Java Key Generation
@Value("${encryption.key}")
String encryptionKey;
private Key generateKey(String salt) throws Exception {
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] hash = md.digest((encryptionKey + salt).getBytes("UTF-8"));
byte[] key = Arrays.copyOf(hash, 16);
return new SecretKeySpec(key, ALG);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment