code: public static String privateKey2String(PrivateKey key) {
          PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(key.getEncoded());
          return new String(Base64.getEncoder().encode(spec.getEncoded()), StandardCharsets.UTF_8);
      }
docs: Put this in a safe place obviously.
  @param key the key
  @return base 64 encoded string of the PKCS8 spec