Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating a License Key based on a particular string, and then given the License key how to get back the string #1298

Open
rameshdk12 opened this issue Nov 9, 2024 · 0 comments

Comments

@rameshdk12
Copy link

Crypto++ Issue Report

Thanks for taking the time to report an issue. Reporting issues helps us improve stability and reliability for all users, so it is a valuable contribution.

Please do not ask questions in the bug tracker. Please ask questions on the Crypto++ Users List at http://groups.google.com/forum/#!forum/cryptopp-users.

Please do not ask questions about unsupported build systems, like Autotools, CMake, Conan and NuGet. They are other people's projects. We don't know anything about them.

Please do not ask questions at Stack Overflow. We do not patrol Stack Overflow. We will not be able to answer your question.

There is a wiki page with information on filing useful bug reports. If you have some time please visit http://www.cryptopp.com/wiki/Bug_Report on the wiki. The executive summary is:

  • State the operating system and version (Ubutnu 17 x86_64, Windows 7 Professional x64, etc)
  • State the version of the Crypto++ library (Crypto++ 7.0, Master, etc)
  • State how you built the library (Visual Studio, Makefile, distro provided, etc)
  • Show a typical command line (the output of the compiler for cryptlib.cpp)
  • Show the link command (the output of the linker for libcryptopp.so or cryptest.exe)
  • Show the exact error message you are receiving (copy and paste it); or
  • Clearly state the undesired behavior (and state the expected behavior)

HI,
I am trying to generate license keys for a software that I have written.
how can I Generate a License Key based on a particular string, and then given the License key how to get back the string
I know very little cryptography .I just need small piece of code to accomplish this.
Using internet managed to get the below code for the first part:
#include <cryptopp/rsa.h>
#include <cryptopp/osrng.h>
#include <cryptopp/base64.h>
#include <cryptopp/filters.h>
#include <cryptopp/hex.h>
#include
#include

using namespace CryptoPP;

std::string generateLicenseKey(const std::string& email) {
AutoSeededRandomPool rng;

// Generate RSA keys
InvertibleRSAFunction params;
params.GenerateRandomWithKeySize(rng, 2048);

RSA::PrivateKey privateKey(params);
RSA::PublicKey publicKey(params);

// Sign the email
RSASSA_PKCS1v15_SHA_Signer signer(privateKey);
std::string signature;
StringSource(email, true,
	new SignerFilter(rng, signer,
		new StringSink(signature)
	)
);

// Encode the signature in base64
std::string encoded;
StringSource(signature, true,
	new /*Base64Encoder*/HexEncoder(
		new StringSink(encoded)
	)
);

return encoded;

}
int main() {
std::string email = "[email protected]";
std::string licenseKey = generateLicenseKey(email);
std::cout << "License Key: " << licenseKey << std::endl;
return 0;
}

secondpart(to be done):
How do I decode and get back the string(email) given the license key?
Regards,
Ramesh D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant