javascript - Python rsa加密问题
原来是在HTML中使用jsencrypt来加密:
var encrypt = new JSEncrypt();
<code> encrypt.setPublicKey('MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCp0wHYbg/NOPO3nzMD3dndwS0MccuMeXCHgVlGOoYyFwLdS24Im2e7YyhB0wrUsyYf0/nhzCzBK8ZC9eCWqd0aHbdgOQT6CuFQBMjbyGYvlVYU2ZP7kG9Ft6YV6oc9ambuO7nPZh+bvXH0zDKfi02prknrScAKC0XhadTHT3Al0QIDAQAB'); var encrypted_input1 = encrypt.encrypt($('#input1').val()); var encrypted_input2 = encrypt.encrypt($('#input2').val()); var ajax_data = { input1: encrypted_input1, input2: encrypted_input2, remember: $('#remember_me').prop('checked') }; </code>
想用Python的库rsa来实现同样的加密:
name = 'Adam_LBQ'#input1
password = '123456' #input2
我的实现代码如下:
coding:utf-8
import rsa
name = 'Adam_LBQ'
password = '123456'
pub_key = #?怎么写啊
rsa_name = rsa.encrypt(name,pub_key)
rsa_password = rsa.encrypt(password,pub_key)
print rsa_name +'\n'+ rsa_password
我是模拟登陆来爬去内容的,希望是加密之后和js加密的内容是一样的,该怎么写啊?
回复内容:
原来是在HTML中使用jsencrypt来加密:
var encrypt = new JSEncrypt();
<code> encrypt.setPublicKey('MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCp0wHYbg/NOPO3nzMD3dndwS0MccuMeXCHgVlGOoYyFwLdS24Im2e7YyhB0wrUsyYf0/nhzCzBK8ZC9eCWqd0aHbdgOQT6CuFQBMjbyGYvlVYU2ZP7kG9Ft6YV6oc9ambuO7nPZh+bvXH0zDKfi02prknrScAKC0XhadTHT3Al0QIDAQAB'); var encrypted_input1 = encrypt.encrypt($('#input1').val()); var encrypted_input2 = encrypt.encrypt($('#input2').val()); var ajax_data = { input1: encrypted_input1, input2: encrypted_input2, remember: $('#remember_me').prop('checked') }; </code>
想用Python的库rsa来实现同样的加密:
name = 'Adam_LBQ'#input1
password = '123456' #input2
我的实现代码如下:
coding:utf-8
import rsa
name = 'Adam_LBQ'
password = '123456'
pub_key = #?怎么写啊
rsa_name = rsa.encrypt(name,pub_key)
rsa_password = rsa.encrypt(password,pub_key)
print rsa_name +'\n'+ rsa_password
我是模拟登陆来爬去内容的,希望是加密之后和js加密的内容是一样的,该怎么写啊?
生成一对RSA的公私钥
如果装了git
打开git bash,输入ssh-keygen -t rsa
一路回车后在c盘用户目录下面有个.ssh目录,进去.pub文件就是公钥文件,也就是这里的pub_key
公钥加密,私钥则用来解密
关于 python
的 rsa
加密
Pycrypto与RSA密码技术笔记

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Golang is better than C in concurrency, while C is better than Golang in raw speed. 1) Golang achieves efficient concurrency through goroutine and channel, which is suitable for handling a large number of concurrent tasks. 2)C Through compiler optimization and standard library, it provides high performance close to hardware, suitable for applications that require extreme optimization.

Discussion on Hierarchical Structure in Python Projects In the process of learning Python, many beginners will come into contact with some open source projects, especially projects using the Django framework...

C interacts with XML through third-party libraries (such as TinyXML, Pugixml, Xerces-C). 1) Use the library to parse XML files and convert them into C-processable data structures. 2) When generating XML, convert the C data structure to XML format. 3) In practical applications, XML is often used for configuration files and data exchange to improve development efficiency.

Discussing the hierarchical architecture problem in back-end development. In back-end development, common hierarchical architectures include controller, service and dao...

Choosing Python or C depends on project requirements: 1) If you need rapid development, data processing and prototype design, choose Python; 2) If you need high performance, low latency and close hardware control, choose C.

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

Python and C each have their own advantages, and the choice should be based on project requirements. 1) Python is suitable for rapid development and data processing due to its concise syntax and dynamic typing. 2)C is suitable for high performance and system programming due to its static typing and manual memory management.
