private SAMLObject encryptNameIdIfNecessary(final SAMLObject subjectNameId,
                                                final SamlProfileBuilderContext context) {
        if (!(subjectNameId instanceof EncryptedID)
            && subjectNameId instanceof final NameID nameId
            && NameIDType.ENCRYPTED.equalsIgnoreCase(nameId.getFormat())) {
            return samlObjectEncrypter.encode(nameId, context.getRegisteredService(), context.getAdaptor());
        }
        return subjectNameId;
    }
This is {@link SamlProfileSamlSubjectBuilder}.

@author Misagh Moayyed
@since 5.0.0
support/cas-server-support-saml-idp-web/src/main/java/org/apereo/cas/support/saml/web/idp/profile/builders/subject/SamlProfileSamlSubjectBuilder.java