Spring is flexible and useful in making industrial(IT) tool.

First Security lesson in Spring MVC

Tarang
2 min readMay 23, 2020

“Small mistakes/errors can help you in evolving as a person /developer”-Anonymous.
24-Jan-2020-I got the task for implementing server side captcha without using third party /any git library. It took me while to understand how many technical lessons it is going to teach me in my work application which is based on @springMVC platform.
1-Captcha with randomized colors and background is needed but Graphics2D object has default black color.
2-In @SpringBoot web app it is easy to implement using Java and Java Server Pages(JSP) but since we are using @AngularJs ,we find difficult to handle the sessions. I look in various Stack Overflow answers but none was working due to @servlet2.5 version. So came with plan of sending encryption of Captcha ,later to receive it.
3- @RSA encryption is an effective encryption algorithm but sending byte[] from server side to client side,encrypted captcha in byte[] is getting loss.
4- Conversion from byte[] to string using @String constructor in java.Now we were able to send/receive the string without any loss. Conversion from string to byte[] could result in loss of data too.
5-To go with lossless conversion from byte[] to string and vice versa we used StandardCharset -UTF-8/16/US-ASCII but none of them work, and not even Base64Encoding.
6-At the end ,we chose different algorithm @AES which encrypts string using secret private key.

It worked …

@SpringBoot is very handy compare to SpringMVC where application.properties file is an epitome doing these configurations on entire applications.

Note: Fellow writers,considering my first post,correct me for my mistakes.

Love to connect to you all.

Regards

Tarang

--

--

Tarang
Tarang

Written by Tarang

0 Followers

aCosmicMonk… A novice but ardent writer.