code: def __build_signature(self, data, saml_type, sign_algorithm=OneLogin_Saml2_Constants.RSA_SHA1):
          
          assert saml_type in ('SAMLRequest', 'SAMLResponse')
          key = self.get_settings().get_sp_key()
  
          if not key:
              raise OneLogin_Saml2_Error(
                  "Trying to sign the %s but can't load the SP private key." % saml_type,
                  OneLogin_Saml2_Error.PRIVATE_KEY_NOT_FOUND
              )
  
          msg = self.__build_sign_query(data[saml_type],
                                        data.get('RelayState', None),
                                        sign_algorithm,
                                        saml_type)
  
          sign_algorithm_transform_map = {
              OneLogin_Saml2_Constants.DSA_SHA1: xmlsec.Transform.DSA_SHA1,
              OneLogin_Saml2_Constants.RSA_SHA1: xmlsec.Transform.RSA_SHA1,
              OneLogin_Saml2_Constants.RSA_SHA256: xmlsec.Transform.RSA_SHA256,
              OneLogin_Saml2_Constants.RSA_SHA384: xmlsec.Transform.RSA_SHA384,
              OneLogin_Saml2_Constants.RSA_SHA512: xmlsec.Transform.RSA_SHA512
          }
          sign_algorithm_transform = sign_algorithm_transform_map.get(sign_algorithm, xmlsec.Transform.RSA_SHA1)
  
          signature = OneLogin_Saml2_Utils.sign_binary(msg, key, sign_algorithm_transform, self.__settings.is_debug_active())
          data['Signature'] = OneLogin_Saml2_Utils.b64encode(signature)
          data['SigAlg'] = sign_algorithm
docs: Builds the Signature
          :param data: The Request data
          :type data: dict
  
          :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