Required to encrypt passwords on the client side (Java applet). The password must be encrypted with a private key, and the public one must be sent to the database, which would then get it and decrypt it. The key pair is generated as follows:
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(2048); KeyPair keyPair = keyPairGenerator.generateKeyPair(); PublicKey publicKey = keyPair.getPublic(); PrivateKey privateKey = keyPair.getPrivate();
And with such keys, encryption and the reverse action occur without problems, but in order to store the key in the database, the toString () method converts it to a string. And how to make the same line of type PublicKey?