import rsa content = 'hello,world!@#$%^&*()_+' with open('pubkey.pem', mode='rb') as f: pubkey = rsa.PublicKey.load_pkcs1(f.read()) with open('privkey.pem', mode='rb') as f: prikey = rsa.PrivateKey.load_pkcs1(f.read()) crypto = rsa.encrypt(content.encode(), pubkey) print(crypto.hex()) crypto = bytes.fromhex('24cb974ad7d5673bfc9e7bca3ad66d2365f52ef5cb6cdbc72f1bb5877cf358fcffc3ed34682b205d8b4a8982e979e9ef7f6f2250220f271fcbb2f733ee68a511acb49edbd437fc2798b7eaf7d890c72a7c5ce98254940fa1f40c44deecacd57b97576570f30a3704ba31949cd37e6ed5e594827e524d5a03341293cf767e38af2d8dbe089d370f12454e3290c6071d861940611855dbcd62f7b5dda5af2afb91c8d7c8545242d5bb9b88f49feb969f6d18ad6eea9947e8ced1a0e0aae4b025eb0225753dca9e796652def27bff7d77b1a5c97cd95e9bf638d2e33cd21b0bb0e9d3e3b0fc490b181ed6933ea555792f86ac0ea438479f4d66f1404d93924eeaff05f2d533ba710e11d7018ecda1eb1490c60e23a92d855a0de2f1d811382bf6b49bafd69c507b84d2e1ab7816fcfdc7393d4207ebd7260ec9711e9a180b3263e16e590f7eb15b163f4ccc55147530aa8ba6c34272060d8befc19703c1d1e199cbca80fa47869d8f80a1053d227abd519f9ce17bb09d676fda6ca5c3e547231df9aafba2a8ced35ace7b79087129b373535c3057b6042484ace1d03d982605ea268d6c454f5096b54c528f8373fb4b90d2b7cdb658d7cbd31035efddbbc2e443d0a106d450392d503cb3f2082b4607d070aa090649bc443fe54e7c95ed6059b3aa1a42154169a09c3481ee863c41cf6a7ee2ce05670b5a5cce9259a41669b4e647') content2 = rsa.decrypt(crypto, prikey).decode() print(content2, len(content2), len(content2.encode()))