简单软件授权方案
1、获取机器码,发给软件开发者
2、开发者用机器码加密得到一个密文 发给使用者
3、使用者 用这个密文 与本地计算密文比较密文是否一致,一致就把密文写入到注册表,下次登录从注册表读密文对比。
(最重要的是密文生成的方法保密)(只需加密,不用解密)
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
std::string encryptDecrypt(const std::string& input, const char key) {
std::string output = input;
for (size_t i = 0; i < input.size(); ++i) {
output[i] = input[i] ^ key;
}
return output;
}
std::string toHexString(const std::string& input) {
std::stringstream ss;
for (const auto& c : input) {
ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(c);
}
return ss.str();
}
std::string fromHexString(const std::string& input) {
std::string output;
std::stringstream ss;
for (size_t i = 0; i < input.size(); i += 2) {
int value;
ss << std::hex << input.substr(i, 2);
ss >> value;
output.push_back(static_cast<char>(value));
ss.clear();
}
return output;
}
int main(int argc, char* argv[]) {
std::string input = "Hello, World!";
if (argc != 2) {
std::cout << "Usage: " << " <filename> <orignal string>" << std::endl;
std::cout << "示例: <filename> "<<input << std::endl;
}
else
{
input = argv[1];
}
std::cout << "原字符串: " << input << std::endl;
char key = 'K';
std::string encrypted = encryptDecrypt(input, key);
std::cout << "加密后的字符串: " << encrypted << std::endl;
std::string hexString = toHexString(encrypted);
std::cout << "加密后的16进制字符串: " << hexString << std::endl;
std::string decrypted = encryptDecrypt(fromHexString(hexString), key);
std::cout << "解密后的字符串: " << decrypted << std::endl;
return 0;
}