/** * Returns the RSA private key encoded in <a href="https://tools.ietf.org/html/rfc5208">PKCS * #8</a> <a href="https://tools.ietf.org/html/rfc7468">PEM format</a>. */ public String privateKeyPkcs8Pem() { StringBuilder result = new StringBuilder(); result.append("-----BEGIN PRIVATE KEY-----\n"); encodeBase64Lines(result, ByteString.of(keyPair.getPrivate().getEncoded())); result.append("-----END PRIVATE KEY-----\n"); return result.toString(); }
/** * Returns the certificate encoded in <a href="https://tools.ietf.org/html/rfc7468">PEM * format</a>. */ public String certificatePem() { try { StringBuilder result = new StringBuilder(); result.append("-----BEGIN CERTIFICATE-----\n"); encodeBase64Lines(result, ByteString.of(certificate.getEncoded())); result.append("-----END CERTIFICATE-----\n"); return result.toString(); } catch (CertificateEncodingException e) { throw new AssertionError(e); } }
/** * Returns the RSA private key encoded in <a href="https://tools.ietf.org/html/rfc8017">PKCS * #1</a> <a href="https://tools.ietf.org/html/rfc7468">PEM format</a>. */ public String privateKeyPkcs1Pem() { if (!(keyPair.getPrivate() instanceof RSAPrivateKey)) { throw new IllegalStateException("PKCS1 only supports RSA keys"); } StringBuilder result = new StringBuilder(); result.append("-----BEGIN RSA PRIVATE KEY-----\n"); encodeBase64Lines(result, pkcs1Bytes()); result.append("-----END RSA PRIVATE KEY-----\n"); return result.toString(); }
/** * Returns the RSA private key encoded in <a href="https://tools.ietf.org/html/rfc5208">PKCS * #8</a> <a href="https://tools.ietf.org/html/rfc7468">PEM format</a>. */ public String privateKeyPkcs8Pem() { StringBuilder result = new StringBuilder(); result.append("-----BEGIN PRIVATE KEY-----\n"); encodeBase64Lines(result, ByteString.of(keyPair.getPrivate().getEncoded())); result.append("-----END PRIVATE KEY-----\n"); return result.toString(); }
/** * Returns the RSA private key encoded in <a href="https://tools.ietf.org/html/rfc8017">PKCS * #1</a> <a href="https://tools.ietf.org/html/rfc7468">PEM format</a>. */ public String privateKeyPkcs1Pem() { if (!(keyPair.getPrivate() instanceof RSAPrivateKey)) { throw new IllegalStateException("PKCS1 only supports RSA keys"); } StringBuilder result = new StringBuilder(); result.append("-----BEGIN RSA PRIVATE KEY-----\n"); encodeBase64Lines(result, pkcs1Bytes()); result.append("-----END RSA PRIVATE KEY-----\n"); return result.toString(); }
/** * Returns the certificate encoded in <a href="https://tools.ietf.org/html/rfc7468">PEM * format</a>. */ public String certificatePem() { try { StringBuilder result = new StringBuilder(); result.append("-----BEGIN CERTIFICATE-----\n"); encodeBase64Lines(result, ByteString.of(certificate.getEncoded())); result.append("-----END CERTIFICATE-----\n"); return result.toString(); } catch (CertificateEncodingException e) { throw new AssertionError(e); } }