protected Pair<String, String> generateCertificateAndKey() throws Exception {
        try (val certWriter = new StringWriter(); val keyWriter = new StringWriter()) {
            configurationContext.getSamlIdPCertificateAndKeyWriter().writeCertificateAndKey(keyWriter, certWriter);
            val encryptionKey = configurationContext.getMetadataCipherExecutor().encode(keyWriter.toString());
            return Pair.of(certWriter.toString(), encryptionKey);
        }
    }
Write metadata.

@param metadata          the metadata
@param registeredService registered service
@return the string
@throws Throwable the throwable
support/cas-server-support-saml-idp-core/src/main/java/org/apereo/cas/support/saml/idp/metadata/generator/BaseSamlIdPMetadataGenerator.java