@WebServlet(
description = "generator servlet",
urlPatterns = {"/generator"})
public class generator extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, Exception {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String pr = request.getParameter("product");
String clientsCount = request.getParameter("numUser");
String otpCount = request.getParameter("numOtp");
String lices = request.getParameter("licesee");
String Date = request.getParameter("date");
String certPeriod = request.getParameter("certPeriod");
String pass = request.getParameter("pass");
String lic = request.getParameter("license");
String outFile = "C:\\Users\\Samsung\\Desktop\\keys\\temp\\asd.lic";
String keyFile = "C:\\Users\\Samsung\\Desktop\\keys\\lic.aks";
if (pr != null && clientsCount != null && otpCount != null && lices != null && Date != null && certPeriod != null && pass != null && lic != null) {
try {
ArrayList<String> snlist = new ArrayList<String>();
for (int i = 0; i < 10; i++) {
snlist.add(pr);
snlist.add(clientsCount);
snlist.add(otpCount);
snlist.add(lices);
snlist.add(Date);
snlist.add(certPeriod);
snlist.add(outFile);
snlist.add(keyFile);
snlist.add(pass);
snlist.add(lic);
}
Properties props = new Properties();
props.put("ActiveOtpCount", otpCount);
props.put("ActiveClientsCount", clientsCount);
props.put("Licensee", lices);
props.put("LicenseExpired", Date);
props.put("CertificatesPeriod", new Long(certPeriod));
LicenseGenerator.init();
KeyStore ks = KeyStore.getInstance("AKS", AkSigProv.PROV_NAME);
ks.load(new FileInputStream(keyFile), pass.toCharArray());
String a = ks.aliases().nextElement();
PrivateKey pk = (PrivateKey) ks.getKey(a, pass.toCharArray());
X509Certificate cert = (X509Certificate) ks.getCertificate(a);
out.println("<h1>" + new String(Base64.encode(cert.getEncoded())) + "</h1>");
String x = LicenseGenerator.generateLicense(pr, snlist, props, cert, pk);
try (FileOutputStream fos = new FileOutputStream(outFile)) {
fos.write(x.getBytes());
}
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
out.print("ERROR!");
}
}