Here you can find the source of createRandomKey(int size)
public static String createRandomKey(int size)
//package com.java2s; import java.util.Random; public class Main { private static final char[] HEX_DIGITS = "0123456789ABCDEF" .toCharArray();/*from w w w .ja v a 2 s.co m*/ public static String createRandomKey(int size) { char[] c = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' }; Random random = new Random(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < size; i++) { sb.append(c[Math.abs(random.nextInt()) % c.length]); } return sb.toString(); } public static final String toString(byte[] ba) { return toString(ba, 0, ba.length); } public static final String toString(byte[] ba, int offset, int length) { char[] buf = new char[length * 2]; for (int i = 0, j = 0, k; i < length;) { k = ba[offset + i++]; buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F]; buf[j++] = HEX_DIGITS[k & 0x0F]; } return new String(buf); } }