用于将加密的SHA256代码解密为crypto++中的字符串的代码
Code to decrypt the encrypted SHA256 code into string in crypto++
我使用crypto++对字符串进行加密和解密。代码如下所示。该代码对用户名和密码进行加密。但我不知道如何将它再次解密成字符串。是什么代码将加密后的SHA256代码解密成字符串。有人能帮我吗?
#include <cryptopp/hex.h>
#include <cryptopp/sha.h>
#include <cryptopp/base64.h>
#include <iostream>
#include <string>
int main()
{
CryptoPP::SHA256 hash;
byte digest[CryptoPP::SHA256::DIGESTSIZE];
std::string username, password, salt, output;
std::cout << "Enter username: ";
std::getline(std::cin,username);
std::cout << std::endl << "Enter password: ";
std::getline(std::cin,password);
salt = username + password;
hash.CalculateDigest(digest,(const byte *)salt.c_str(),salt.size());
CryptoPP::HexEncoder encoder;
CryptoPP::StringSink *SS = new CryptoPP::StringSink(output);
encoder.Attach(SS);
encoder.Put(digest,sizeof(digest));
encoder.MessageEnd();
std::cout << "The username/password salted hash is => " << output << std::endl;
return 0;
}
正如评论者已经指出的,此代码不是执行加密,而是执行hashing。主要的区别在于,散列在设计上是不可逆的。这在密码应用程序中很重要,因为您明确不希望以任何可访问的形式存储用户的密码,而只希望对其进行检查。
所以,简而言之:你不能"解密"你的散列。
当你想检查提供的密码是否正确时,你可以像在代码中一样再次对其进行散列,并将散列与原始密码的散列进行比较。
相关文章:
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 代码在main()中运行,但在函数中出现错误
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 编译包含字符串的代码时遇到问题
- 我在c++代码中生成了一个运行时#3异常
- 如何在linux终端中同时编译和运行c++代码
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 在Linux for Windows上编译C++代码时出错
- 我的字符计数代码计算错误.为什么
- 孤立代码块在结构中引发异常
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 此代码是否违反一个定义规则
- 为什么我的代码在输出中增加了93天
- 我的简单if-else语句是如何无法访问的代码
- 使用动态分配的数组会导致代码分析发出虚假的C6386缓冲区溢出警告
- 构建和链接 Crypto++ 的测试代码
- 在Linux中集成Crypto++代码到Qt应用程序
- 用于将加密的SHA256代码解密为crypto++中的字符串的代码