Skip to content

Instantly share code, notes, and snippets.

@gschueler
Created July 13, 2023 17:51
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 gschueler/e6f47dafcf14e952a09a66bf2804c1b9 to your computer and use it in GitHub Desktop.
Save gschueler/e6f47dafcf14e952a09a66bf2804c1b9 to your computer and use it in GitHub Desktop.
generate random key
import java.security.*;
def len=256
if(args.length>0){
len = Integer.parseInt(args[0])
}
byte[] sharedKey = new byte[len]
new SecureRandom().nextBytes(sharedKey)
//log the random key
println(Base64.encoder.encodeToString(sharedKey))
@DanielWeintraub
Copy link

I think this is equivalent:

> head -c 256 /dev/urandom | base64

@gschueler
Copy link
Author

this is too easy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment