def __build_signature(self, saml_data, relay_state, saml_type, sign_algorithm=OneLogin_Saml2_Constants.RSA_SHA1):
assert saml_type in ['<STR_LIT>', '<STR_LIT>']<EOL>key = self.__settings.get_sp_key()<EOL>if not key:<EOL><INDENT>raise OneLogin_Saml2_Error(<EOL>"<STR_LIT>" % saml_type,<EOL>OneLogin_Saml2_Error.PRIVATE_KEY_NOT_FOUND<EOL>)<EOL><DEDENT>dsig_ctx = xmlsec.DSigCtx()<EOL>dsig_ctx.signKey = xmlsec.Key.loadMemory(key, xmlsec.KeyDataFormatPem, None)<EOL>msg = '<STR_LIT>' % (saml_type, quote_plus(saml_data))<EOL>if relay_state is not None:<EOL><INDENT>msg += '<STR_LIT>' % quote_plus(relay_state)<EOL><DEDENT>msg += '<STR_LIT>' % quote_plus(sign_algorithm)<EOL>sign_algorithm_transform_map = {<EOL>OneLogin_Saml2_Constants.DSA_SHA1: xmlsec.TransformDsaSha1,<EOL>OneLogin_Saml2_Constants.RSA_SHA1: xmlsec.TransformRsaSha1,<EOL>OneLogin_Saml2_Constants.RSA_SHA256: xmlsec.TransformRsaSha256,<EOL>OneLogin_Saml2_Constants.RSA_SHA384: xmlsec.TransformRsaSha384,<EOL>OneLogin_Saml2_Constants.RSA_SHA512: xmlsec.TransformRsaSha512<EOL>}<EOL>sign_algorithm_transform = sign_algorithm_transform_map.get(sign_algorithm, xmlsec.TransformRsaSha1)<EOL>signature = dsig_ctx.signBinary(str(msg), sign_algorithm_transform)<EOL>return b64encode(signature)<EOL>
Builds the Signature
:param saml_data: The SAML Data
:type saml_data: string

:param relay_state: The target URL the user should be redirected to
:type relay_state: string

:param saml_type: The target URL the user should be redirected to
:type saml_type: string  SAMLRequest | SAMLResponse

:param sign_algorithm: Signature algorithm method
:type sign_algorithm: string