We’ve been using OpenSSL to create a license key on the server based on some user data (using a private key) and decrypting that also via OpenSSL in the software (using its public counterpart).
But as TheVinn points out, adding OpenSSL as a dependency is kind of a nightmare, also overkill for this case - for us this raised quite some compatibility issues with old versions of OS X and XCode.
We’ve tried to replace OpenSSL with Crpto++ before, which worked on PC, but not on Mac, at least not within an hour of development time.
But: we’ve just successfully replaced the plugin’s part with JUCE’s functions.
So, first we had to convert our public key from PEM format for use in JUCE by running this command on the console:
Using JUCE’s and it’s did not give us results which were compatible with the OpenSSL-encrypted data, but we came up with a different solution which works for us. This code is not at all straightforward, and I am pretty sure there’s a better solution. But I’ll post it anyway as it might be of help for others running into the same issues:
juce::MemoryBlock mbEncrypted = ...; // Holding binary encrypted data.
// Convert memory block, RSA exponent and RSA modulus to <BigInteger>.
juce::String licenseKeyHexString = juce::String::toHexString((unsigned char*)mbEncrypted.getData(), mbEncrypted.getSize(), 0) ;
juce::BigInteger bigInteger;
bigInteger.parseString(licenseKeyHexString, 16);
juce::BigInteger rsaExponent(65537); // Put your public exponent here.
juce::BigInteger rsaModulus;
rsaModulus.parseString("b912e2...30e2", 16); // Put your public modulus here.
// Do decryption.
bigInteger.exponentModulo(rsaExponent, rsaModulus);
// Copy result to <char*>. Note that the result's order is reversed.
const int EXPECTED_LENGTH = 40;
juce::MemoryBlock mbDecrypted = bigInteger.toMemoryBlock();
if(mbDecrypted.getSize() >= EXPECTED_LENGTH)
{
char decrypted[EXPECTED_LENGTH + 1];
p = (char*)mbDecrypted.getData() + (EXPECTED_LENGTH - 1);
for(int i=0; i < EXPECTED_LENGTH; ++i)
{
decrypted[i] = *p;
--p;
}
decrypted[EXPECTED_LENGTH] = 0;
...
}