Javascript-Pythonrsa Encryption

Source: Internet
Author: User
Originally, jsencrypt was used in HTML for encryption: varencryptnewJSEncrypt (); {code ...} to use the Python Library rsa for the same encryption: name & #039; Adam_LBQ & #039; # input1password & #039; 123456 & #039; # input2 my implementation code: coding: utf-8i...

Originally, jsencrypt was used for encryption in HTML:

Var encrypt = new JSEncrypt ();

        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')        };

We want to use the Python Library rsa to implement the same encryption:
Name = 'Adam _ lbq' # input1
Password = '000000' # input2

My implementation code is as follows:

Coding: UTF-8

Import rsa
Name = 'Adam _ lbq'
Password = '000000'
Pub_key = #? How to write?
Rsa_name = rsa. encrypt (name, pub_key)
Rsa_password = rsa. encrypt (password, pub_key)
Print rsa_name + '\ n' + rsa_password
I simulated login to crawl the content, hoping that the encrypted content is the same as that encrypted by js. How can I write it?

Reply content:

Originally, jsencrypt was used for encryption in HTML:

Var encrypt = new JSEncrypt ();

        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')        };

We want to use the Python Library rsa to implement the same encryption:
Name = 'Adam _ lbq' # input1
Password = '000000' # input2

My implementation code is as follows:

Coding: UTF-8

Import rsa
Name = 'Adam _ lbq'
Password = '000000'
Pub_key = #? How to write?
Rsa_name = rsa. encrypt (name, pub_key)
Rsa_password = rsa. encrypt (password, pub_key)
Print rsa_name + '\ n' + rsa_password
I simulated login to crawl the content, hoping that the encrypted content is the same as that encrypted by js. How can I write it?

Generate a pair of RSA public/private keys

If git is installed
Open git bash and enter ssh-keygen-t rsa

After you press enter, There Is A. ssh directory under the user directory on drive C. The. pub file is the public key file, that is, the pub_key here.

Public key encryption. The private key is used for decryption.

AboutpythonOfrsaEncryption

Pycrypto and RSA cryptographic technology notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.