Hi experts
I'm doing a project with RSA encryption a small example, here I generate the two keys public and private encrypted a small message and send the message with the two keys the server must return the message without encrypting so the generated key is correct but I have an error after error. it does not work to give me some help.
anyone who uses the rsa library of andorid studio works perfectly I do not know what I'm missing or what I'm doing wrong
server response:
I'm doing a project with RSA encryption a small example, here I generate the two keys public and private encrypted a small message and send the message with the two keys the server must return the message without encrypting so the generated key is correct but I have an error after error. it does not work to give me some help.
anyone who uses the rsa library of andorid studio works perfectly I do not know what I'm missing or what I'm doing wrong
B4X:
Dim data(0) As Byte
Dim formats(0) As String
Dim su As StringUtils
Dim kpg As KeyPairGenerator
Dim c1 As Cipher
c1.Initialize("RSA/ECB/PKCS1Padding")
kpg.Initialize("RSA", 1024)
kpg.GenerateKey
formats = kpg.Formats
pubkey = kpg.PublicKeyToBytes
prvkey = kpg.PrivateKeyToBytes
Dim clear As String = "prueba de encryptado rsa"
data = Bconv.StringToBytes(clear, "UTF8")
data = c1.Encrypt(data, kpg.PublicKey, False)
Dim pkey As String = su.EncodeBase64(kpg.PublicKeyToBytes)
Dim prikey As String = su.EncodeBase64(kpg.PrivateKeyToBytes)
Dim data1 As String = su.EncodeBase64(data)
Dim j As HttpJob
j.Initialize("", Me)
Dim mapjson As Map
mapjson.Initialize
mapjson.Put("publica",pkey)
mapjson.Put("privada",prikey)
mapjson.Put("mensaje",data1)
js.Initialize(mapjson)
strjson = js.ToString
j.PostString("http://67.205.76.93:8008/decrypt2",strjson)
j.GetRequest.SetContentType("application/json")
Wait For (j) JobDone(j As HttpJob)
If j.Success = False Then
Log(j.ErrorMessage)
Else
Log(j.GetString)
End If
B4X:
{"result":"Error TypeError: Cannot read property 'decrypt' of undefined"}
Last edited: