C++程序中用到MD5和SHA1算法的情况是比较多的,自己写明显不靠谱,openssl库中的调用比较麻烦,网上有些人写的代码真心不靠谱。比如有的在intel平台工作就可以,到了mips平台就工作不正常了,算出来的值是错的。
这里有个比较靠谱的C++代码实现SHA1,供大家参考
https://github.com/xia-chu/ZLToolKit/blob/master/src/Util/SHA1.cpp
https://github.com/xia-chu/ZLToolKit/blob/master/src/Util/MD5.cpp
在x86, x64和mips平台测试通过。
sha256的代码:
https://github.com/notepad-plus-plus/notepad-plus-plus/tree/master/PowerEditor/src/MISC/sha2/sha-256.cpp
多种加密算法的C语言实现版 aes, md5, sha1,des, sha256
https://github.com/xoreaxeaxeax/movfuscator/tree/master/validation/crypto-algorithms