RSA problem


#1

I’m trying to implement licensing via RSA mechanism in Juce, but after decrypting, I get complete trash instead of what was encrypted. I tried to debug it with the following simple code:

RSAKey keyPublic;
RSAKey keyPrivate;
RSAKey::createKeyPair(keyPublic, keyPrivate, 128);

...skipping code that fills memory block mb1...

BitArray val;
val.loadFromMemoryBlock(mb1);
keyPrivate.applyToValue(val);
keyPublic.applyToValue(val);
const MemoryBlock mb2(val.toMemoryBlock());

And as a result, I get trash data in mb2 block, although as I understand, mb2 block should be the same as mb1, right? What can be wrong with all this?


#2

I tried this:

[code]RSAKey keyPublic;
RSAKey keyPrivate;
RSAKey::createKeyPair(keyPublic, keyPrivate, 128);

BitArray val;
val.parseString (“12345678901234567890”, 10);
DBG (val.toString (10));
keyPrivate.applyToValue (val);
DBG (val.toString (10));
keyPublic.applyToValue (val);
DBG (val.toString (10));[/code]

…and it works perfectly. Maybe it’s just your test that’s wrong?


#3

Oh, my example wasn’t exact. I actually created keys in the following way:

int seeds[4] = {599, 170, 12121, 1};
RSAKey keyPublic;
RSAKey keyPrivate;
RSAKey::createKeyPair(keyPublic, keyPrivate, 128, seeds, 4);

And such created keys work as I said. E.g. your example outputs the following:

12345678901234567890
45075836443192048854218600430946615692
106724729699857976931642232957296991457

But if I don’t use seeds, everything is okay. Is there something wrong with my seeds? :slight_smile:


#4

Doh! Yes, there’s a mistake in the way I use the seeds. Have checked-in a fix now!