【发布时间】:2014-08-14 17:02:34
【问题描述】:
我们正在将代码转换为使用 Crypto++ 库。为我们的用户创建一个散列密码是必需的吗?只是想确保我们没有遗漏一些重要的部分。 谢谢你
void test_create_hash(void)
{
using namespace CryptoPP;
std::string password = "this is a users password";
unsigned int iterations = 1000000;
AutoSeededRandomPool rng;
SecByteBlock pwsalt(AES::DEFAULT_KEYLENGTH);
rng.GenerateBlock(pwsalt,pwsalt.size());
SecByteBlock derivedkey(AES::DEFAULT_KEYLENGTH);
PKCS5_PBKDF2_HMAC<SHA256> pbkdf;
pbkdf.DeriveKey(
derivedkey, derivedkey.size(),
0x00,
(byte *) password.data(), password.size(),
pwsalt, pwsalt.size(),
iterations
);
std::string salthex;
StringSource ss1(pwsalt,pwsalt.size(),true,
new HexEncoder(
new StringSink(salthex)
)
);
std::string derivedhex;
StringSource ss2(derivedkey,derivedkey.size(),true,
new HexEncoder(
new StringSink(derivedhex)
)
);
cout << "salt stored to database:" << salthex << std::endl;
cout << "password stored to database:" << derivedhex << std::endl;
}
【问题讨论】:
标签: c++ passwords crypto++ pbkdf2