R
R
random2014-11-17 08:45:59
Java
random, 2014-11-17 08:45:59

License generation?

<html>
    <head>
        <title>generator</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <form action="generator" method="GET">
            Product: <input type="text" name="product"><br>
            ActiveClientsCount: <input type="text" name="numUser"><br>
            ActiveOtpCount: <input type="text" name="numUtp"><br>
            Licesee: <input type="text" name="licesee"><br>
            Data: <input type="text" name="data"><br>
            Certificated period: <input type ="text" name="certPeriod"><br>
            License: <input type="text" name="license"><br>
            Password: <input type="password" name="pass"><br>
            <input type="submit" value="Generate">
        </form>
    </body>
</html>

@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:/temp/asd.lic";
        String keyFile = "C:/keys/lic/lic.aks";

        ArrayList<Long> snlist = new ArrayList<Long>();
        for (int i = 0; i < 10; i++) {
            snlist.add(Long.parseLong(pr));
            snlist.add(Long.parseLong(clientsCount));
            snlist.add(Long.parseLong(otpCount));
            snlist.add(Long.parseLong(lices));
            snlist.add(Long.parseLong(Date));
            snlist.add(Long.parseLong(certPeriod));
            snlist.add(Long.parseLong(outFile));
            snlist.add(Long.parseLong(keyFile));
            snlist.add(Long.parseLong(pass));
            snlist.add(Long.parseLong(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());
            }
        }
    
    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (Exception ex) {
            Logger.getLogger(generator.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
   
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (Exception ex) {
            Logger.getLogger(generator.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

  
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}


I accept data from html and take the key from here (C:/keys/lic/lic.aks), then generate and write to a file, which should be located at (C:/temp/asd.lic).
I click the button but it doesn't create the file. What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai, 2014-11-17
@demon123

Something you have slashes are not screw. Are there any errors in the logs?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question