Private Sub EncryptRSAWithPublicKey(Text As String,PublicKey As String) As String
Dim su As StringUtils
Dim pubkey() As Byte = su.DecodeBase64(PublicKey)
Dim Enc As Cipher
Enc.Initialize("RSA")
Dim kpg As KeyPairGenerator
kpg.Initialize("RSA", 1024)
kpg.PublicKeyFromBytes(pubkey)
Dim bytes() As Byte = Text.GetBytes("UTF8")
Return su.EncodeBase64(Enc.Encrypt(bytes,kpg.PublicKey,False))
End Sub
on B4A the output is allways the same, on B4J the right key is generated and i can decrypt it, but on B4A not.
As far as I understand it seems the private key is in PKCS#1, therefore you initialize the Cipher with "RSA/ECB/PKCS1Padding" in your Post#2. But the KeyPairGenerator expects the private key to be in PKCS#8 when calling kpg.PrivateKeyFromBytes(privkey).