Jump to content
We've recently updated our Privacy Statement, available here ×

Encrypting password using BouncyCastleProvider


Recommended Posts

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 key
cipher.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 Regards
Yiannis

  

Link to comment
Share on other sites

  • 6 months later...
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

  • 1 year later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...