I wanted to ask how to retrieve the actual values of the private and public keys from the KeyPair object because i need to export them and save in a database.
You can simply downcast to RSAPrivateKey and RSAPublicKey. Once you've done that you can access the methods of these classes.
RSAPrivateKey
RSAPublicKey
RSAPublicKey pubKey = (RSAPublicKey) keyPair.getPublic()); BigInteger modulus = pubKey.getModulus();
etc.