B4J Question decryption of private key using RSA and PKCS1_v1_5


I'm trying to port a Python implementation which is used for turning on/off Wifi TP-Link P100 wall plugs or light bulbs.

The way to turn the P100 on or off is in the following order using htpp requests:
- handshaking by means of a key pair (private and public)
- login by username (emailaddress) and password.
- switch the device on /off using a token
At this moment I'm stuck in decoding the returned private key from the plug. The Python script is included and commented.
The lines with cipher puzzles me.
Sub decode_handshake_key(pKey As String) As String
    ' Dim bc As ByteConverter
    Dim su As StringUtils
    Dim decode() As Byte = su.DecodeBase64(pKey)
    Dim decode2() As Byte = privateKey
'    Python script
'   decode: bytes = b64decode(key.encode("UTF-8"))
'    decode2: bytes = self.privateKey
'        cipher = PKCS1_v1_5.new(RSA.importKey(decode2))
'        do_final = cipher.decrypt(decode, None)
'        If do_final Is None:
'            raise ValueError("Decryption failed!")
'        b_arr:bytearray = bytearray()
'        b_arr2:bytearray = bytearray()
'        For i in range(0, 16):
'            b_arr.insert(i, do_final[i])
'        For i in range(0, 16):
'            b_arr2.insert(i, do_final[i + 16])

'        Return tp_link_cipher.TpLinkCipher(b_arr, b_arr2)
    Return "In test"
End Sub ' decode_handshake_key(pKey)
I have studied several examples in this and other forums, but found no solution yet.
Have anyone any ideas on how to do that?

Any help will be much apprecciated
Many thanks, best regards


At the same time I posted this item, I did a further research on Github and found two Java implementations for this Tapo P100 wall plug.
At the moment I'm developing a Java library based on these Java Github ports. I'm now in the testing phase of this library.
Upvote 0