Skip to content

Instantly share code, notes, and snippets.

@andrew-dixon
Created April 15, 2015 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrew-dixon/8363711ee2b9687c57a3 to your computer and use it in GitHub Desktop.
Save andrew-dixon/8363711ee2b9687c57a3 to your computer and use it in GitHub Desktop.
<cfscript>
random = createObject("java", "java.security.SecureRandom");
salt_bytes = javaCast("byte[]", [].set(1,50,0));
iterations = 10000;
key_length = 2048;
password = javaCast("char[]", ['p','a','s','s','w','o','r','d']);
random.nextBytes(salt_bytes);
cryptoSpec = createObject("java", "javax.crypto.spec.PBEKeySpec").init(password, salt_bytes, iterations, key_length);
skf = createObject("java", "javax.crypto.SecretKeyFactory");
keyFactory = skf.getInstance('PBKDF2WithHmacSHA1');
secret = keyFactory.generateSecret(cryptoSpec).getEncoded();
dump(secret);
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment