I have a Spring Boot application which generate an RSA key pair using java.security.KeyPairGenerator and save it in 2 files, Base64 encoded so that keys are readable.
What i'm trying to do is to get the public key with javascript and use it on the client side to encrypt the password field in a login request.
Server will then decrypt the password and check if it's correct.
How can i get server's public key and use it in encryption on client side?
EDIT i've said the password but the encrypted content could be any text a user want to send to the server.
EDIT 2 Using HTTPS or something similar is a better solution and i know it, i'm just asking if it can be done and how