ioannis.anagnostopoulos Posted July 30, 2013 Share Posted July 30, 2013 Hello all,I am new to jasper reports and even newer to the encryption concepts. Not sure if this has been answered before but I am not sure if my encryption code is wrong or I submit the encrypted credentials wrongly. So here is my java back end encryption code:[/code]KeyFactory keyFactory = KeyFactory.getInstance("RSA");RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(modulus, exponent);System.out.println("Got the RSAPublicKey now"); PublicKey key = keyFactory.generatePublic(pubKeySpec); Cipher cipher = Cipher.getInstance("RSA/NONE/NoPadding");System.out.println("nProvider is: " + cipher.getProvider().getInfo());// encrypt the plaintext using the public keycipher.init(Cipher.ENCRYPT_MODE, key);System.out.println("Init the cipher!!!");byte[] cipherText = cipher.doFinal("superuser".getBytes()); System.out.println("Surprise: " + cipherText);String json = gson.toJson(new LoginEncFactory(new String(cipherText)));System.out.println(json); response.setContentType("application/json");PrintWriter out = response.getWriter();out.print(json);out.flush();So providing that my json object in this example comes out as:{"userName":"superuser","password":"xªJTdÖu003c?®u001e:oÜÆu0001]U*ý÷ |aó¿âãæ؆u0003YtA°Kö‘ƒìkÎÝ羟…Ýi^ æ¦:?™L•u0007Èu0011´£,4úuOÊGu000e‰u001ehø›stu0012êu0012Ëu0007°,v›6u000eÄÔu0005u0012©™9€0ã-ª7‘KÑ}Ä"RÌm+u003cÝL-(þÕóԵʻ~u0003ü"} If I submit in the front end j_username=superuser&j_password=..... via my ajax XMLHttpRequest I get nowhere (access denied). But I am not sure if my encryption is wrong or the way I submit the encrypted credentials to jasper server. Any help will be much appreciated. Below is the ajax code: http = new XMLHttpRequest(); [/code]if ("withCredentials" in http) { http.withCredentials = true; } [/code]var url = "http://la01981:7001/jasperserver-pro/rest/login"; [/code]var params = "j_username=" + credentials.userName + "&j_password=" + credentials.password; [/code]alert("Will login with: " + params); [/code]http.open("POST", url, true); //Send the proper header information along with the request [/code]http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); [/code]http.setRequestHeader("Content-length", params.length); [/code]http.setRequestHeader("Origin", "http://la01981:8080"); [/code]http.setRequestHeader("charset", "utf-8");[/code]http.send(params);[/code] Kind RegardsYiannis Link to comment Share on other sites More sharing options...
bogartlisa Posted February 18, 2014 Share Posted February 18, 2014 did you get this working? I may be headed down the same path soon and have the same questions. Link to comment Share on other sites More sharing options...
ioannis.anagnostopoulos Posted February 18, 2014 Author Share Posted February 18, 2014 Yes I did. I will post the solution tomorrow :) Link to comment Share on other sites More sharing options...
nazaf Posted January 20, 2016 Share Posted January 20, 2016 Did you post the solution? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now