Android Question Encrypt data with third party key

hery71

Member
Licensed User
Hi in B4A i want to know if it s possible for encrypting text with public and private key that the payement platform gave me before. Because i saw in many example that key ar generated automatically by keygenerator.
But i need that to encrypt with third party private or public key?
Best regards
 

hery71

Member
Licensed User
pvkey:
 Dim Publickey as string
 Dim kpg As KeyPairGenerator
 publickey="ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789" 'This is not my reel key
 Dim pubkey() As Byte = su.DecodeBase64(PublicKey)
 Enc.Initialize("RSA/ECB/PKCS1Padding")
 kpg.Initialize("RSA", 64)
 kpg.PublicKeyFromBytes(pubkey)
 Dim bytes() As Byte = Text.GetBytes("UTF8")
 Return su.EncodeBase64(Enc.Encrypt(bytes,kpg.PublicKey,False))
Thank you @Erel i tried that!!!
but i have error after:
java.security.spec.InvalidKeySpecException: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: Error parsing public key
Is it mean that the public key is not valid?
Thank you in advance
 
Upvote 0

hery71

Member
Licensed User
Ok i will check the provider tomorow morning if the key is RSA OPENSSL or other; and i will advice you after
Posting public or private key here is not safe ??? or iits wrong....
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Upvote 0

hery71

Member
Licensed User
ok this is the public key : 45eb2329869217a08c0858cc0d8bf81b4dc8df445e48e8a17e
waiting your analyze
 
Upvote 0

hery71

Member
Licensed User
The system is CBC
They gave me the IV the private key and the public key
Do you have the code for encrypt and decrypt?
Best regards
Hery
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Hm. Are you really sure that this is RSA? The length is 200 Bits (25 Bytes * 8). Should be based on a multiple of 16 like 1024, 2048 or better.. Beneath to this it looks more like a AES-Key. IV and CBC points to AES, too. With AES there's only one key (symetric). Could you check this?
 
Upvote 0

hery71

Member
Licensed User
Hi yes its Triple DES, mode CBC, with IV
i try to change the code from forum
But if you have the code it's welcome
Best regards
Hery
 
Upvote 0

hery71

Member
Licensed User
HI this is my code:
code:
    Dim Bconv As ByteConverter
    Dim key(0) As Byte
    Dim data(0) As Byte
    Dim ivb(0) As Byte
    Dim c As Cipher
    Dim su As StringUtils
    Dim privatekey2 As String = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 'I mask my privatekey
    Dim pubkey() As Byte = su.DecodeBase64(privatekey2)
    Dim publickey2 As String = "45eb2329869217a08c0858cc0d8bf81b4dc8df445e48e8a17e"
    Dim privkey() As Byte = su.DecodeBase64(publickey2)
    ivb=  "xxxxxxxxxxxxxxxx".GetBytes("UTF8") 'Not the Real IV 


    Dim xdata = "HELLO CBC"
    Dim xdatebyte() As Byte =   su.DecodeBase64(xdata)
    ' use DES for variable length data using padding
    Dim kg As KeyGenerator
    Dim c As Cipher
    'DESede/mpmp/PKCS5Padding
    c.Initialize("DESEDE/CBC/PKCS5Padding") ' replace "DES/" with "AES/" for Rijndael or "DESEDE/" for triple DES
    ' CBC needs an initialisation vector
    c.InitialisationVector = ivb
    'Encrypt
    kg.Initialize("DESede") ' replace "DES" with "AES" for Rijndael or "DESEDE" for triple DES
    kg.KeyFromBytes(pubkey)
    Dim data() As Byte
    data= c.Encrypt(xdatebyte,kg.Key,True)
    'Decrypt
    kg.Initialize("DESede") ' replace "DES" with "AES" for Rijndael or "DESEDE" for triple DES
    kg.KeyFromBytes(privkey)
    Dim Ddata() As Byte
    Ddata= c.Decrypt(data,kg.Key,True)

And i have this message error at the encrypt line
java.security.InvalidKeyException: key size must be 128 or 192 bits
Problem with my public key????
Best regards
 
Upvote 0

hery71

Member
Licensed User
This is the parameters the provider gave me

crypting system: Triple DES
IV ="XXXXXXXXXX/XXXXX" (Lenght=16)
Mode: CBC
Publickey "XXXXXXXXXXXX....." (Lenght = 50 for crypting )
Private key "XXXXXXX......" (Lenght = 50 for decrypting)

That ALL
 
Upvote 0

hery71

Member
Licensed User
The document is in french !!!!i dont know if you can tranlate it
the rest of information is by mail:

Add info:
crypting system: Triple DES
IV ="XXXXXXXXXX/XXXXX" (Lenght=16)
Mode: CBC

I wish it can help you to solve it
 

Attachments

  • Intégration paiement-Copier.pdf
    379.9 KB · Views: 976
Upvote 0

hery71

Member
Licensed User
see the document please i put in yellow the encript information and the 2nd document is the adding iformation b email
BR
 

Attachments

  • yellow en_integration doc-Copier.pdf
    430 KB · Views: 149
  • Email from the paiment provider.pdf
    30.5 KB · Views: 155
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…