Last active
November 20, 2022 17:30
-
-
Save danielfreitasce/f2bfd42f38a26e6af90c77d21f0ec8f6 to your computer and use it in GitHub Desktop.
Generate Random Strings in Apex
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
//Option 1 | |
String myRandomString = EncodingUtil.convertToHex(Crypto.generateAesKey(128)).substring(0, 32) | |
//Option 2 | |
Integer len = 32; | |
Blob blobKey = crypto.generateAesKey(192); | |
String key = EncodingUtil.base64encode(blobKey); | |
String myRandomString = key.substring(0,len); | |
//Option 2.1 | |
Integer len = 32; | |
String myRandomString = EncodingUtil.base64encode(Crypto.generateAesKey(192)).substring(0,len); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment