Unverified Commit 4f5c084a authored by cyjseagull's avatar cyjseagull Committed by GitHub
Browse files

fix gm mac calculation error (#112)

parent 8d17efb2
{
"address": "0x64C40b7E82A4A5acFC5acE6422590Ac4Ce5F0BDB",
"address": "0x7fe7097870bb7C63b3718096dd7EB08ADC85b57F",
"encrypt": true,
"private_key": "fJknVt3c7Q7jU/IMuXAtJPqsziI12ayZ6KuTeyrEMiKthfGbiZH8L1rT4FzjTu8zM2tESg1PqKKcZZDaHmoWhyd9iRC+anRerBXAKO3GFUg=",
"private_key": "qzBCfflxrZgHAVYyPemTr6xhXU4ovDrpxXaAyU+CjdsuemGm+C98HLN3L5cj5vrVwvGor9o/0YC3Hw6xEBn6lJcrxukIIBAOg+H6EL3fQRw=",
"type": "gm",
"mac": "3a11d41dd2847c61c575de0dd4e03d46bb0a9e270689d6145dd6b812c3b60ab5"
"mac": "0dd56145b6604312f036d2b35fc8199f0270f5101a013a5e5967445772ed761a"
}
\ No newline at end of file
......@@ -75,7 +75,7 @@ class GM_Account(object):
content["private_key"] = key
content["type"] = "gm"
# set mac of the password
passwdBytes = bytes(decode_hex(password))
passwdBytes = bytes(password, "utf-8")
content["mac"] = sm3.sm3_hash(passwdBytes)
with open(filename, "w") as dump_f:
json.dump(content, dump_f, indent=4)
......@@ -94,7 +94,7 @@ class GM_Account(object):
# get and compare mac
expected_mac = content["mac"]
password = self.pwd_ljust(password)
passwdBytes = bytes(decode_hex(password))
passwdBytes = bytes(password, "utf-8")
mac = sm3.sm3_hash(passwdBytes)
if not hmac.compare_digest(mac, expected_mac):
raise ValueError("MAC mismatch")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment