
package de.passau.uni.sec.compose.id.core.service;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

import javax.xml.bind.DatatypeConverter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@Service
public class Random {

	private static Logger LOG = LoggerFactory.getLogger(ServiceObjectService.class);

	public String getRandomToken() 
	{
		byte[] array = new byte[33];
		SecureRandom random;
		try {
			random = SecureRandom.getInstance("SHA1PRNG");
			random.nextBytes(array);
			
		} catch (NoSuchAlgorithmException e) {

			sun.security.provider.SecureRandom r = new sun.security.provider.SecureRandom();
			r.engineNextBytes(array);
			LOG.warn("Using a newly created SecureRandom object to generate tokens for SO: SHA1PRNG instance of SecureRandom was not found!");
			
		}
		String token = DatatypeConverter.printBase64Binary(array);
		return token;
	}

}

@@ -171,16 +171,60 @@
 erter;%0A%0A
+import org.apache.commons.codec.binary.Hex;%0A
 import o
@@ -240,16 +240,16 @@
 Logger;%0A
-
 import o
@@ -452,16 +452,19 @@
 ring get
+Hex
 RandomTo
@@ -468,16 +468,794 @@
 mToken()
+%0A%09%7B%0A%09%09char%5B%5D allowed = %220123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ%22.toCharArray();%0A%09    StringBuilder result = new StringBuilder();%0A%09    try %7B%0A%09%09    %09for (int i=0;i%3C38; i++)%0A%09%09    %09%7B%0A%09%09    %09%09result.append(allowed%5BMath.abs(SecureRandom.getInstance(%22SHA1PRNG%22).nextInt())%25allowed.length%5D);%0A%09%09    %09%7D%0A%09%09    %09return result.toString();%0A%09    %0A%09    %7D catch (NoSuchAlgorithmException e) %7B%0A%09    %09%0A%09    %09byte%5B%5D array = new byte%5B33%5D;%0A%09%09%09sun.security.provider.SecureRandom r = new sun.security.provider.SecureRandom();%0A%09%09%09r.engineNextBytes(array);%0A%09%09%09LOG.warn(%22Using a newly created SecureRandom object to generate tokens for SO: SHA1PRNG instance of SecureRandom was not found!%22);%0A%09%09%09return Hex.encodeHexString(array);%0A%09%09%09%0A%09%09%7D%0A%09    %0A%09%7D%0A%09%0A%09public String getInitialToken()
  %0A%09%7B%0A%09%09b
@@ -1753,16 +1753,16 @@
 array);%0A
-
 %09%09return
@@ -1773,10 +1773,80 @@
 en;%0A%09%7D%0A%0A
+%09public String getRandomToken() %0A%09%7B%0A%09%09return getHexRandomToken();%0A%09%7D%0A%0A
 %7D%0A

Change to return only to chars and numbers, request by David due to Apollo issue.