Closed ffalcinelli closed 8 years ago
Hey Fabio, thanks for using the library :)
The problem is your Encryption endpoint and the way you're invoking it. You're taking the whole body (@RequestBody String test
) as input in your endpoint, and when doing the curl, you're sending it as FORM data by default (without specifying content-type).
So when you capture the Request Body in your endpoint and is converted to String, Spring finds that you only defined one parameter mytext
that has no value, so its literally "mytext=" in URL form enconded format. Since you're sending --data mytext
Change your encrypt
method in JasyptController
to this:
@RequestMapping(method = RequestMethod.POST)
public
@ResponseBody
String encrypt(
@RequestParam("text") String text) {
String encrypted = stringEncryptor.encrypt(text.trim());
logger.info("ORIGINAL: " + text);
logger.info("ENCRYPTED: " + encrypted);
logger.info("DECRYPTED: " + stringEncryptor.decrypt(encrypted));
return String.format("ENC(%s)", encrypted);
}
Notice the change from @RequestBody
to @RequestParam("text")
. So when you invoke it from curl, you need to send a parameter called text
in your URL-encoded-form data:
$ curl localhost:8080/encrypt --data text=mytext
ENC(nWdKNNDGamuA+79stkv5ww==)
Best Regards, Uli
No words... You're right and I'm feeling totally silly! I'm sorry for having wasted your time, thank you a lot!
No worries man, glad I could help. If you like the library please give it a star. Best, Uli
I'm experiencing a very strange issue. When using encrypted password with an Oracle datasource
I always get an Invalid username/password error:
It works in plaintext. So I've wrote a very simple controller just for testing purposes, this is the controller code
while this is the custom configuration made in Application class (1to1 copy from the project readme)
This is how I invoke it
And this is the log:
So I think the problem resides in an additional base64 padding performed somewhere on the decrypted value... Really strange. Any advice? Or maybe am I missing something?
Thanks in advance, and best regards, Fabio