Table of Contents
coding:utf-8
回复内容:
Home Backend Development PHP Tutorial javascript - Python rsa加密问题

javascript - Python rsa加密问题

Jun 06, 2016 pm 08:17 PM
c++ java javascript php python

原来是在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>
Copy after login
Copy after login

想用Python的库rsa来实现同样的加密:
name = 'Adam_LBQ'#input1
password = '123456' #input2

我的实现代码如下:

coding:utf-8

import rsa
name = 'Adam_LBQ'javascript - Python rsa加密问题
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>
Copy after login
Copy after login

想用Python的库rsa来实现同样的加密:
name = 'Adam_LBQ'#input1
password = '123456' #input2

我的实现代码如下:

coding:utf-8

import rsa
name = 'Adam_LBQ'javascript - Python rsa加密问题
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

公钥加密,私钥则用来解密

关于 pythonrsa 加密

Pycrypto与RSA密码技术笔记

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Golang and C  : Concurrency vs. Raw Speed Golang and C : Concurrency vs. Raw Speed Apr 21, 2025 am 12:16 AM

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.

Does Python projects need to be layered? Does Python projects need to be layered? Apr 19, 2025 pm 10:06 PM

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   and XML: Exploring the Relationship and Support C and XML: Exploring the Relationship and Support Apr 21, 2025 am 12:02 AM

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.

How to correctly divide business logic and non-business logic in hierarchical architecture in back-end development? How to correctly divide business logic and non-business logic in hierarchical architecture in back-end development? Apr 19, 2025 pm 07:15 PM

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

Python vs. C  : Which Language to Choose for Your Project? Python vs. C : Which Language to Choose for Your Project? Apr 21, 2025 am 12:17 AM

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.

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

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 vs. JavaScript: Use Cases and Applications Compared Python vs. JavaScript: Use Cases and Applications Compared Apr 21, 2025 am 12:01 AM

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 vs. C  : Understanding the Key Differences Python vs. C : Understanding the Key Differences Apr 21, 2025 am 12:18 AM

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.

See all articles