@staticmethod<EOL><INDENT>def generate_name_id(value, sp_nq, sp_format=None, cert=None, debug=False, nq=None):<DEDENT>
doc = Document()<EOL>name_id_container = doc.createElementNS(OneLogin_Saml2_Constants.NS_SAML, '<STR_LIT>')<EOL>name_id_container.setAttribute("<STR_LIT>", OneLogin_Saml2_Constants.NS_SAML)<EOL>name_id = doc.createElement('<STR_LIT>')<EOL>if sp_nq is not None:<EOL><INDENT>name_id.setAttribute('<STR_LIT>', sp_nq)<EOL><DEDENT>if nq is not None:<EOL><INDENT>name_id.setAttribute('<STR_LIT>', nq)<EOL><DEDENT>if sp_format is not None:<EOL><INDENT>name_id.setAttribute('<STR_LIT>', sp_format)<EOL><DEDENT>name_id.appendChild(doc.createTextNode(value))<EOL>name_id_container.appendChild(name_id)<EOL>if cert is not None:<EOL><INDENT>xml = name_id_container.toxml()<EOL>elem = fromstring(xml, forbid_dtd=True)<EOL>error_callback_method = None<EOL>if debug:<EOL><INDENT>error_callback_method = print_xmlsec_errors<EOL><DEDENT>xmlsec.set_error_callback(error_callback_method)<EOL>mngr = xmlsec.KeysMngr()<EOL>file_cert = OneLogin_Saml2_Utils.write_temp_file(cert)<EOL>key_data = xmlsec.Key.load(file_cert.name, xmlsec.KeyDataFormatCertPem, None)<EOL>key_data.name = basename(file_cert.name)<EOL>mngr.addKey(key_data)<EOL>file_cert.close()<EOL>enc_data = EncData(xmlsec.TransformAes128Cbc, type=xmlsec.TypeEncElement)<EOL>enc_data.ensureCipherValue()<EOL>key_info = enc_data.ensureKeyInfo()<EOL>enc_key = key_info.addEncryptedKey(xmlsec.TransformRsaOaep)<EOL>enc_key.ensureCipherValue()<EOL>enc_ctx = xmlsec.EncCtx(mngr)<EOL>enc_ctx.encKey = xmlsec.Key.generate(xmlsec.KeyDataAes, <NUM_LIT>, xmlsec.KeyDataTypeSession)<EOL>edata = enc_ctx.encryptXml(enc_data, elem[<NUM_LIT:0>])<EOL>newdoc = parseString(tostring(edata, encoding='<STR_LIT>').encode('<STR_LIT:utf-8>'), forbid_dtd=True)<EOL>if newdoc.hasChildNodes():<EOL><INDENT>child = newdoc.firstChild<EOL>child.removeAttribute('<STR_LIT>')<EOL>child.removeAttribute('<STR_LIT>')<EOL>child.setAttribute('<STR_LIT>', OneLogin_Saml2_Constants.NS_XENC)<EOL>child.setAttribute('<STR_LIT>', OneLogin_Saml2_Constants.NS_DS)<EOL><DEDENT>nodes = newdoc.getElementsByTagName("<STR_LIT:*>")<EOL>for node in nodes:<EOL><INDENT>if node.tagName == '<STR_LIT>':<EOL><INDENT>node.tagName = '<STR_LIT>'<EOL>node.removeAttribute('<STR_LIT>')<EOL>node.setAttribute('<STR_LIT>', OneLogin_Saml2_Constants.NS_DS)<EOL><DEDENT>else:<EOL><INDENT>node.tagName = '<STR_LIT>' + node.tagName<EOL><DEDENT><DEDENT>encrypted_id = newdoc.createElement('<STR_LIT>')<EOL>encrypted_data = newdoc.replaceChild(encrypted_id, newdoc.firstChild)<EOL>encrypted_id.appendChild(encrypted_data)<EOL>return newdoc.saveXML(encrypted_id)<EOL><DEDENT>else:<EOL><INDENT>return doc.saveXML(name_id)<EOL><DEDENT>
Generates a nameID.

:param value: fingerprint
:type: string

:param sp_nq: SP Name Qualifier
:type: string

:param sp_format: SP Format
:type: string

:param cert: IdP Public Cert to encrypt the nameID
:type: string

:param debug: Activate the xmlsec debug
:type: bool

:param nq: IDP Name Qualifier
:type: string

:returns: DOMElement | XMLSec nameID
:rtype: string