Python makes nail-nail encryption/decryption tool _python

Source: Internet
Author: User
Tags assert decrypt

It is a long time did not write technical blog, cover because of recent learning knowledge, also did not sum up what is worth sharing content, so has been stopped pen so far. Recent work and nails have been developed, and the authorities have not provided any Python SDK, so they have to write them all themselves. I will now share the "encryption/decryption/signature" portion of the implementation of the relative cost of time, hoping to help some people.

The specific mechanism of encryption/decryption can refer to the official documentation.

To install this extension in your project, you can use: pip install dingtalk_crypto install.

Using the method, you can refer to the following test code:

#-*-Coding:utf-8-*-import json from dingtalk_crypto import Dingtalkcrypto # This is the nail official test data # @see Https://open-doc. dingtalk.com/doc2/detail.htm?treeid=175&articleid=104945&doctype=1 Encrypt_text = ' 1a3nbxmcfwkcjvfoq7whjhb+ix3qhpsc9jbadzne1i03peok1laoqorz3+nlygnhwmwj3vdmg ' \ ' + Ozrhmeizi7gtrwvdubmfxjz8ej23jvya9vryej5as7xm/zpulx8neqis44w53h1qagnc3przm7zc ' \ '/ d6ibr0rguathb6zrhp8pyrfgnnos9phsbdhlegk+agganfwjxuq9+0pzcy0w9lq== ' crypto = Dingtalkcrypto (' 4g5j64qlyl3zvetqxz5jiocdr586fn2zvjpa8zls3ij ', ' 123456 ', ' suite4xxxxxxxxxxxxxxx ') signature = ' 5a65ceeef9aab2d149439 f82dc191dd6c5cbe2c0 ' timestamp = ' 1445827045067 ' nonce = ' nexhmp4r ' class Testcrypto:def Test_decrypt (self): Rand str, length, msg, Suite_key = Crypto.decrypt (encrypt_text) msg = json.loads (msg) assert msg[' eventtype '] = = ' Chec K_create_suite_url ' assert msg[' Random '] = = ' LPIDSNLF ' assert suite_key = ' suite4xxxxxxxxxxxxxxx ' def test_enc Ode (self): encrypt_msg= Crypto.encrypt (' Hello World ') randstr, Length, msg, Suite_key = Crypto.decrypt (encrypt_msg) assert msg = ' Hello

  World ' Def test_check_signature (self): Assert crypto.check_signature (Encrypt_text, timestamp, nonce, signature) 
    def test_sign (self): msg = crypto.encrypt (' Hello World ') Actual_sig, actual_time, actual_nonce = crypto.sign (msg)

 Assert True

Finally, post the project's source address, hoping to have some communication.

Related Article

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.