def sign(self, body):
     # assemble character string to sign
     sign_str = self.config.user_code + self.config.app_code + body['body']["userName"] + body['body']["nonce"] \
                + body['body']["chainCode"] + body['body']["funcName"] + \
                array_sort(body['body']["args"]) + map_sort(body['body']["transientData"])
     # The string is signed with SHA256WITHECDSA using the user's private key certificate, and the ecdsa_sign method is called to generate base64-formatted MAC values.
     mac = self.config.encrypt_sign.sign(sign_str).decode()
     return mac
Ejemplo n.º 2
0
 def sign(self, body):
     # 拼接待签名的字符串
     sign_str = self.config.user_code + self.config.app_code + body['body']["userName"] + body['body']["nonce"] \
                + body['body']["chainCode"] + body['body']["funcName"] + \
                array_sort(body['body']["args"]) + map_sort(body['body']["transientData"])
     # 对字符串 使用用户私钥证书进行 SHA256WITHECDSA 签名,调用ecdsa_sign方法生成base64格式mac值
     mac = self.config.encrypt_sign.sign(sign_str).decode()
     return mac
Ejemplo n.º 3
0
    def verify(self, res_data):
        verify_str = str(res_data["header"]["code"]) + res_data["header"]["msg"] + \
                     str(res_data['body']["blockHash"]) + str(res_data['body']["blockNumber"]) + \
                     res_data['body']["preBlockHash"] + str(res_data['body']["blockSize"]) + \
                     str(res_data['body']["blockTxCount"]) + array_sort(res_data['body']["transactions"])

        signature = res_data['mac']
        # Call the ecdsa_verify function to verify the signature
        return self.config.encrypt_sign.verify(verify_str, signature)
Ejemplo n.º 4
0
    def verify(self, res_data):
        verify_str = str(res_data["header"]["code"]) + res_data["header"]["msg"] + array_sort(res_data['body'])

                     # str(res_data['body']["eventId"]) + str(res_data['body']["eventKey"]) + \
                     # str(res_data['body']["notifyUrl"]) + str(res_data['body']["attachArgs"]) + \
                     # str(res_data['body']["createTime"]) + str(res_data['body']["orgCode"]) + \
                     # str(res_data['body']["userCode"]) + str(res_data['body']["appCode"]) + \
                     # str(res_data['body']["chainCode"])

        signature = res_data['mac']
        # Call the ecdsa_verify function to verify the signature
        return self.config.encrypt_sign.verify(verify_str, signature)