Code example for SecureRandom

Methods: nextBytes

0
    static String base64Encode(final byte[] data) {
        return Base64.encodeBytes(data);
    } 
 
    static byte[] getRandomBytes(final int size) {
        final SecureRandom random = new SecureRandom();
        final byte[] bytes = new byte[size];
        random.nextBytes(bytes);
        return bytes;
    } 
 
    static String getRandomString() {
        final SecureRandom random = new SecureRandom();
        return String.valueOf(random.nextLong());
    } 
 
    static byte[] getRawBytes(final String text) {
        try { 
            return text.getBytes(CryptoHelper.ENC_UTF8);
        } catch (final UnsupportedEncodingException e) {
            return text.getBytes();