title: convert RSA Publickey to base64 and vice versa
body: <p>I have a publicKey/privateKey pair generated from this function:</p>
  
  <pre><code>public static void generateKey() {
          try {
              final KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM);
              keyGen.initialize(2048);
              final KeyPair key = keyGen.generateKeyPair();
  
              File privateKeyFile = new File(PRIVATE_KEY_FILE);
              File publicKeyFile = new File(PUBLIC_KEY_FILE);
  
              // Create files to store public and private key
              if (privateKeyFile.getParentFile() != null) {
                  privateKeyFile.getParentFile().mkdirs();
              }
              privateKeyFile.createNewFile();
  
              if (publicKeyFile.getParentFile() != null) {
                  publicKeyFile.getParentFile().mkdirs();
              }
              publicKeyFile.createNewFile();
  
              // Saving the Public key in a file
              ObjectOutputStream publicKeyOS = new ObjectOutputStream(
                      new FileOutputStream(publicKeyFile));
              publicKeyOS.writeObject(key.getPublic());
              publicKeyOS.close();
  
              // Saving the Private key in a file
              ObjectOutputStream privateKeyOS = new ObjectOutputStream(
                      new FileOutputStream(privateKeyFile));
              privateKeyOS.writeObject(key.getPrivate());
              privateKeyOS.close();
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      }
  </code></pre>
  
  <p>Now I want to convert publicKey to <code>base64</code> while writing and use that base64 decode to get publicKey back ,how can that be done?</p>