我正在使用python编写一个爬虫。该网站使用JSEncrypt加密密码。 JS代码如下:
var pubkey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDB3Xn/+WP5OVbA8hCj3zuTlqAJ+CVt5UPHi1TYTbsBzEZ0W0+tgn9YElA9hNIi5ElFTicpGCYW4w+B2zmniSLKy3sqItT1wNCt6zGJ7lkUCkhLSIY4mp9Tqs8hn01/3HNnqDRBPhFcmA99Vy+SOoTUvCOUMiGp4ENruyxkvEp5vwIDAQAB"
var encrypt = new JSEncrypt();
encrypt.setKey(pubkey)
encrypt.encrypt("123")
我的python代码是:
from Crypto.Cipher import PKCS1_v1_5
from Crypto.PublicKey import RSA
import base64
pubkey = '''-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDB3Xn/+WP5OVbA8hCj3zuTlqAJ
+CVt5UPHi1TYTbsBzEZ0W0+tgn9YElA9hNIi5ElFTicpGCYW4w+B2zmniSLKy3sq
ItT1wNCt6zGJ7lkUCkhLSIY4mp9Tqs8hn01/3HNnqDRBPhFcmA99Vy+SOoTUvCOU
MiGp4ENruyxkvEp5vwIDAQAB
-----END PUBLIC KEY-----'''
rsa_key = RSA.importKey(pubkey)
cipher = PKCS1_v1_5.new(rsa_key)
print base64.b64encode(cipher.encrypt("123"))
但他们的结果却不同。此外,我发现这些代码每次调用时都会产生不同的加密输出。使用相同的密钥和明文,rsa算法不应该返回相同的输出吗?