通过以下方式调用verify_sha256_hash(密码,hash_expected)
密码,hash_expected ='快速的棕色狐狸跳过懒狗',
结果是“ 94acf27cc065449e756a4f164ed5a7d6d53e51cc4112344dad890cece525c141” 而不是我们从命令行中获得的信息,而是以为他们正在调用相同的openssl二进制文件。
即
$ echo“快速的棕色狐狸跳过了懒狗” | openssl dgst -sha256
(stdin)= c03905fcdab297513a620ec81ed46ca44ddb62d41cbbd83eb4a5a3592be26a69
或 $ echo“快速的棕色狐狸跳过了懒狗” | openssl sha256
(stdin)= c03905fcdab297513a620ec81ed46ca44ddb62d41cbbd83eb4a5a3592be26a69
以下是调用的Python代码:
def verify_sha256_hash(passcode, hash_expected):
command = 'echo "' + passcode + '" | ' + openssl_path + 'openssl dgst -sha256'
process_resultant = subprocess_cmd(command)
if (process_resultant == hash_expected):
print('Verification OK')
else:
print('Verification OK NOT')
return
def subprocess_cmd(command):
process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
print("command: ", command)
process_resultant = str(process.communicate()[0].strip())
process_resultant = process_resultant.lstrip('b\'(stdin)= ').rstrip('\'')
print("process_resultant: ", process_resultant)
return process_resultant
如何纠正?谢谢。