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.