Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.security.SecureRandom;

public class Main {
    public static String randomBytesAsHexString(int byteCount) {
        SecureRandom rng = new SecureRandom();
        byte[] randomData = new byte[byteCount];

        rng.nextBytes(randomData);

        StringBuilder builder = new StringBuilder();

        for (byte byteValue : randomData) {
            builder.append(String.format("%02x", byteValue));
        }

        return builder.toString();
    }
}