我正在对网站进行逆向工程。在网站的代码中,
C = n("720d")
w = new C["JSEncrypt"];
w.setPublicKey(k.privateKey);
k = {
privateKey: "30820122300d06092a864886f70d01010105000382010f003082010a0282010100f357429c22add0d547ee3e4e876f921a0114d1aaa2e6eeac6177a6a2e2565ce9593b78ea0ec1d8335a9f12356f08e99ea0c3455d849774d85f954ee68d63fc8d6526918210f28dc51aa333b0c4cdc6bf9b029d1c50b5aef5e626c9c8c9c16231c41eef530be91143627205bbbf99c2c261791d2df71e69fbc83cdc7e37c1b3df4ae71244a691c6d2a73eab7617c713e9c193484459f45adc6dd0cba1d54f1abef5b2c34dee43fc0c067ce1c140bc4f81b935c94b116cce404c5b438a0395906ff0133f5b1c6e3b2bb423c6c350376eb4939f44461164195acc51ef44a34d4100f6a837e3473e3ce2e16cedbe67ca48da301f64fc4240b878c9cc6b3d30c316b50203010001",
encrypt: function() {
var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "";
return w.encrypt(e)
}
他们定义w
和k
如上,并用它加密字符串,如下所示。
k.encrypt("text goes here")
加密输出如下。
zrvsLtC+A+Ix8Dq/BoRqwRLaI72zOK0TgpJ7KdXEF6spBMYyv6boOzN0yhxA1cKCAImWsaFT7/JRTbBNj40b+qREkE7aNo9gymM4kHH/+u4oFm+2+vLZXBAWGApt9g585tpVLbwOa6ANE2CBLOt8MeZl4smteJq5rKMddRtDosodfdZWTTt8aTbJrgCgkFPzNyYmN+koxwsbZ1VW2MmLtCnIlEIZfDkOkU0WWzcOylLlpG6/Gs0LkRzsY8HoG4ttY0prb8JDlFcuSi+tdLptoSMABJlXZ0mZOAmcElye47QWlq3RlaxF8saJAjthJpsZABiwIRaVUt/X7i6Uunen9A==
我很确定那w
只是JSEncrypt
. 好像当一个字符串被给出时,它只是用JSEncrypt
它k.privateKey
作为公钥加密字符串。
我想用 Python 3 实现同样的目标。
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5 as Cipher_PKCS1_v1_5
from base64 import b64decode,b64encode
pubkey = "30820122300d06092a864886f70d01010105000382010f003082010a0282010100f357429c22add0d547ee3e4e876f921a0114d1aaa2e6eeac6177a6a2e2565ce9593b78ea0ec1d8335a9f12356f08e99ea0c3455d849774d85f954ee68d63fc8d6526918210f28dc51aa333b0c4cdc6bf9b029d1c50b5aef5e626c9c8c9c16231c41eef530be91143627205bbbf99c2c261791d2df71e69fbc83cdc7e37c1b3df4ae71244a691c6d2a73eab7617c713e9c193484459f45adc6dd0cba1d54f1abef5b2c34dee43fc0c067ce1c140bc4f81b935c94b116cce404c5b438a0395906ff0133f5b1c6e3b2bb423c6c350376eb4939f44461164195acc51ef44a34d4100f6a837e3473e3ce2e16cedbe67ca48da301f64fc4240b878c9cc6b3d30c316b50203010001"
msg = "text goes here"
keyDER = b64decode(pubkey)
keyPub = RSA.importKey(keyDER)
cipher = Cipher_PKCS1_v1_5.new(keyPub)
cipher_text = cipher.encrypt(msg.encode())
emsg = b64encode(cipher_text)
print(emsg)
我正在尝试使用 PyCrypto 库,但由于公钥看起来与其他公钥不同,因此会发生错误。
Traceback (most recent call last):
File "/Users/pi/Desktop/test/app.py", line 13, in <module>
keyPub = RSA.importKey(keyDER)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Crypto/PublicKey/RSA.py", line 682, in importKey
raise ValueError("RSA key format is not supported")
ValueError: RSA key format is not supported
我怎样才能实现与 JSEncrypt 对 Python 所做的相同的事情?