问题描述
我正在使用一个小工具来帮助我通过重复记住密码.我想输入密码,该密码每天只能记住一次,而不是每次会话之前都可以记住.当然,我自己不会存储密码,但会很乐意存储其哈希值.
I'm making a little utility to help me remember passwords by repetition. I'd like to enter password to be remembered only once every day and not before each session. Of course, I wouldn't store a password itself, but would gladly store its hash.
那么,使用C ++标准库从std::string
获取哈希的最简单方法是什么?
So, what are the easiest ways to get a hash from std::string
using the C++ Standard Library?
推荐答案
对于不涉及外部库的快速解决方案,可以使用hash<std::string>
哈希string
.通过包含头文件hash_map
或unordered_map
(或其他一些文件)来定义.
For a quick solution involving no external libraries, you can use hash<std::string>
to hash string
s. It's defined by including the header files hash_map
or unordered_map
(or some others too).
#include <string>
#include <unordered_map>
hash<string> hasher;
string s = "heyho";
size_t hash = hasher(s);
如果您决定要增加SHA的安全性,并且不需要其他所有功能,则不必下载大型的Crypto ++库.互联网上有很多独立的实现,只需搜索"sha实现c ++"即可.
If you decide you want the added security of SHA, you don't have to download the large Crypto++ library if you don't need all its other features; there are plenty of standalone implementations on the internet, just search for "sha implementation c++".
这篇关于如何哈希std :: string?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!