Roberto Sánchez
2014-02-21 8cc95fdfbe8146af8d5d4bcac7f7b9e3e2eb95c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package net.curisit.securis;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import net.curisit.securis.beans.RequestBean;
import net.curisit.securis.utils.LicUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ReqGenerator {
   @SuppressWarnings("unused")
   private static final Logger log = LoggerFactory.getLogger(ReqGenerator.class);
   private static ReqGenerator singleton = new ReqGenerator();
   private byte[] LOGO_SECRET;
   private ReqGenerator() {
       try {
           LOGO_SECRET = "Logo ipsum s3cr3t test áíóú".getBytes("utf-8");
       } catch (UnsupportedEncodingException e) {
           e.printStackTrace();
       }
   }
   public static ReqGenerator getInstance() {
       return singleton;
   }
   public RequestBean createRequest(String appCode, String customerCode) throws SeCurisException {
       RequestBean req = new RequestBean();
       req.setAppCode(appCode);
       req.setCustomerCode(customerCode);
       req.setArch(HWInfo.getArch());
       req.setCrcLogo(getCrcLogo());
       req.setMacAddresses(HWInfo.getMACAddress());
       req.setOsName(HWInfo.getOsName());
       return req;
   }
   private String getCrcLogo() {
       String logResource = "images/logo_customer.png";
       InputStream is = getClass().getClassLoader().getResourceAsStream(logResource);
       try {
           String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LOGO_SECRET);
           return shaLogo;
       } catch (IOException e) {
           log.error("Customer logo was not found in classpath in " + logResource, e);
           return null;
       }
   }
}