code: public static String encodePublicKey(PublicKey key) {
          byte[] bytes = key.getEncoded();
          return BEGIN + "\n" + new String(Base64.encodeBase64Chunked(bytes), StandardCharsets.UTF_8).trim() + "\n" + END;
      }
docs: Encodes the given {@link PublicKey} <em>without wrapping</em>. Since a
  public key is public, this is a convenience method provided to convert it
  to a String for unprotected storage.
  <p>
  This method internally calls {@link ByteArray#toBase64(byte[])},
  passing the value of {@link PublicKey#getEncoded()}.
  
  @param key The {@link PublicKey} to be encoded.
  @return A String representation (base64-encoded) of the raw
  {@link PublicKey}, for ease of storage.