code: public static String RSAKeyToString (PublicKey key)
      {
          try {
              KeyFactory kf = KeyFactory.getInstance("RSA");
              RSAPublicKeySpec spec = kf.getKeySpec(key, RSAPublicKeySpec.class);
              StringBuilder buf = new StringBuilder();
              buf.append(spec.getModulus().toString(16))
                  .append(SPLIT)
                  .append(spec.getPublicExponent().toString(16));
              return buf.toString();
          } catch (GeneralSecurityException gse) {
              log.warning("Failed to convert key to string", gse);
          }
          return null;
      }
docs: Converts an key to a string suitable for a properties file.