Soo.... I'm still working on my encrypted installer. I've decided on RSA because of the public/private key nature and am using CryptoEX to do so.
I read here ( RSA Private Key Encryption - CodeProject ) that you should be able to sign data with the private key and decrypt it with the public.
But when I try this with my app - it doesn't seem to work.
I generated my public/private keys with this code originally:
Then I've got the following code:
The encrypt piece seems to work and it can create license.bin - but when I go to decrypt it, it dies on the Rsa.ImportKey(rebuiltpublickey()) line with an error of : "bad key".
Any ideas?
EDIT:
I should add my goal is to be able to create keys with my PC based app and the private key. Then I'm writing a second piece that would just have the public key and would reside on the PPC device side to decrypt the data. But right now I'm testing this all on the PC.
I read here ( RSA Private Key Encryption - CodeProject ) that you should be able to sign data with the private key and decrypt it with the public.
But when I try this with my app - it doesn't seem to work.
I generated my public/private keys with this code originally:
B4X:
'Make new Public/Private Key
privatekey() = Rsa.ExportKey(True)
publickey() = Rsa.ExportKey(False)
FileOpen(c1,"privatekey.bin",cRandom)
Bin.New1(c1,True)
bin.WriteBytes(privatekey())
FileClose(c1)
FileOpen(c1,"publickey.bin",cRandom)
Bin.New1(c1,True)
bin.WriteBytes(publickey())
FileClose(c1)
'End Making New Keys
Then I've got the following code:
B4X:
'regen public key
FileOpen(c1,"publickey.bin",cRandom)
bin.New1(c1,True)
arraysize = FileSize("publickey.bin")
Dim rebuiltpublickey(arraysize) As byte
bin.ReadBytes(rebuiltpublickey(),arraysize)
FileClose(c1)
'regen private key
FileOpen(c1,"privatekey.bin",cRandom)
bin.New1(c1,True)
arraysize = FileSize("privatekey.bin")
Dim rebuiltprivatekey(arraysize) As byte
bin.ReadBytes(rebuiltprivatekey(),arraysize)
FileClose(c1)
'encrypt data
FileOpen(c1,"license.bin",cRandom)
Rsa.ImportKey(rebuiltprivatekey())
code() = Rsa.EncryptString(b64key,False)
Bin.New1(c1,True)
bin.WriteBytes(code())
FileClose(c1)
'getsize & data from license.bin
FileOpen(c1,"license.bin",cRandom)
bin.New1(c1,True)
arraysize = FileSize("license.bin")
Dim code(arraysize) As byte
bin.ReadBytes(code(),arraysize)
FileClose(c1)
'decrypt license.bin
FileOpen(c1,"testresults-decrypted.txt",cWrite)
Rsa.ImportKey(rebuiltpublickey())
decode = Rsa.DecryptString(code(),False)
FileWrite(c1,decode)
origdata = b64.Base64ToString(decode)
FileWrite(c1,origdata)
FileClose(c1)
End Sub
The encrypt piece seems to work and it can create license.bin - but when I go to decrypt it, it dies on the Rsa.ImportKey(rebuiltpublickey()) line with an error of : "bad key".
Any ideas?
EDIT:
I should add my goal is to be able to create keys with my PC based app and the private key. Then I'm writing a second piece that would just have the public key and would reside on the PPC device side to decrypt the data. But right now I'm testing this all on the PC.
Last edited: