Huawei Modem/Router sending encrypted requests
This relates to my Huawei python API here . I'm adding a dedicated post on this as I expect it may be useful for others. This took me quite a while to get working and I couldn't find any working solutions online. This implements the javascript RSA encryption used for encrypting requests to be sent to the modem's underlying API in python. The javascript code is: function RSAEncrypt(text) { var m = pkcs1pad2(text,(this.n.bitLength()+7)>>3); if(m == null) return null; var c = this.doPublic(m); if(c == null) return null; var h = c.toString(16); if((h.length & 1) == 0) return h; else return "0" + h; } The python code I got working is: import uuid import hashlib import hmac from binascii import hexlify import math import base64 from Crypto.Cipher import PKCS1_v1_5 from Crypto.PublicKey.RSA import construct def rsa_encrypt(rsae, rsan, data): if (data is None or data == ''): return '' N = long(rsan,16) E = long(rsae,16) ...