Create a dingtalk encryption/Decryption tool in Python and decrypt it in python.

Source: Internet
Author: User

Create a dingtalk encryption/Decryption tool in Python and decrypt it in python.

I haven't written a technical blog for a long time. Because I have been learning knowledge recently and have not summed up anything worth sharing, I have been suspended. Recent work and dingtalk development have been handed over. The official website does not provide any Python SDK, so you can only write it on your own. Now I want to share the "encryption, decryption, and signature" section, which is relatively time-consuming.

For details about the encryption/decryption mechanism, refer to the official documentation.

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

For instructions, refer to the following test code:

#-*-Coding: UTF-8-*-import jsonfrom dingtalk_crypto import DingTalkCrypto # This is the official dingtalk test data # @ see https://open-doc.dingtalk.com/doc2/detail.htm? TreeId = 175 & articleId = 104945 & docType = 1 # s14encrypt_text = 'encrypt + decrypt '\' + encrypt/decrypt '\'/decrypt + AGGanfwjXuQ9 + 0pzcy0w9scsi = 'crypto = DingTalkCrypto ('4g5j64qlyl3zvetqxz5jiocdr586fn2zvjpa8zls3ij ', '200', 'suite4xxxxxxxxxxxxxxxxxx') signature = 'hangzhou' timestamp = '000000' nonce = 'nexhmp4r 'class TestCrypto: def test_decrypt (self): randstr, length, msg, suite_key = crypto. decrypt (encrypt_text) msg = json. loads (msg) assert msg ['eventtype'] = 'check _ create_suite_url 'assert msg ['rand'] = 'lpidsnlf 'assert suite_key = 'suite4xxxxxxxxxxxxxx' def test_encode (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, paste the Source Code address of the project and hope to have some exchanges.

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.