Skip to content

Instantly share code, notes, and snippets.

@frankvilhelmsen
Last active August 29, 2015 14:21
Show Gist options
  • Save frankvilhelmsen/1aad4287e8d216e00499 to your computer and use it in GitHub Desktop.
Save frankvilhelmsen/1aad4287e8d216e00499 to your computer and use it in GitHub Desktop.
create request with an encrypted token
/* create token for accessing service */
format = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
timestamp = format.format(new Date(System.currentTimeMillis()))
sks = new javax.crypto.spec.SecretKeySpec("OuH5pmYeLIkqiirwiyvY+w==".getBytes(), "AES")
cip = javax.crypto.Cipher.getInstance("AES")
cip.init(javax.crypto.Cipher.ENCRYPT_MODE, sks, cip.getParameters());
raw = cip.doFinal( timestamp.getBytes() );
println "Token..: ${raw.encodeBase64()} "
http://blog.dornea.nu/2014/07/01/on-java-openssl-crypto-blowfish-and-stuff/
String.metaClass.tohex = { ->
return String.format("%x", new BigInteger(1, delegate.getBytes(/*YOUR_CHARSET?*/)));
}
println "timestamp".tohex()
// echo "timestamp" | openssl enc -aes128 -pass pass:OuH5pmYeLIkqiirwiyvY+w== -p -nosalt -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment