我想在PHP中计算十六进制值的摘要。当我尝试使用下面的方法时,它会产生输出,但输出错误。我需要将十六进制值作为二进制格式传递给openssl_digest
函数,我不知道该怎么做。
openssl_digest("d18b5be5aaa7b5d65c8c4cc1a86b081f6f42c86af071f234f5abeb3c54132fa000000001", "sha256");
Output: e545ada40e461a01c1778e0ec16800234938e448b41d3d437bdb76a900436616
Expected: 5910bcacfd66fba4f880d9f291d243710b08176505015bd8408d8b5c4aaa7a52
如何计算真实输出?
答案 0 :(得分:0)
只需将您的十六进制字符串转换为二进制hex2bin
:
openssl_digest(hex2bin("d18b5be5aaa7b5d65c8c4cc1a86b081f6f42c86af071f234f5abeb3c54132fa000000001"), "sha256");
//string '5910bcacfd66fba4f880d9f291d243710b08176505015bd8408d8b5c4aaa7a52' (length=64)