It's been a long time without writing technical blog, cover because of the recent learning knowledge, also did not summarize what is worth sharing content, so has been stopped pen so far. Recent work and nail development has been handed over, and the official does not provide any Python SDK, so it can only be written on its own. Now I share it with the "encryption/decryption/signature" section of the time-consuming phase, hoping to help some people.
The specific mechanism for encrypting/decrypting can refer to the official documentation.
To install this extension in your project, you can use:
Pip Install Dingtalk_crypto
Installation.
Using the method, you can refer to the following test code:
#-*-Coding:utf-8-*-import jsonfrom dingtalk_crypto Import dingtalkcrypto# This is the official test data for the nails # @see Https://open-doc.dingta Lk.com/doc2/detail.htm?treeid=175&articleid=104945&doctype=1#s14 encrypt_text = ' 1a3NBxmCFwkCJvfoQ7WhJHB+ Ix3qhpsc9jbadzne1i03peok1laoqorz3+nlygnhwmwj3vdmg ' \ ' +ozrhmeizi7gtrwvdubmfxjz8ej23jvya9vryej5as7xm/ Zpulx8neqis44w53h1qagnc3przm7zc ' \ '/d6ibr0rguathb6zrhp8pyrfgnnos9phsbdhlegk+agganfwjxuq9+0pzcy0w9lq== ' crypto = Di Ngtalkcrypto (' 4g5j64qlyl3zvetqxz5jiocdr586fn2zvjpa8zls3ij ', ' 123456 ', ' suite4xxxxxxxxxxxxxxx ') signature = ' 5a65ceeef9aab2d149439f82dc191dd6c5cbe2c0 ' timestamp = ' 1445827045067 ' nonce = ' nexhmp4r ' class Testcrypto:def Test_ Decrypt (self): randstr, Length, msg, Suite_key = Crypto.decrypt (encrypt_text) msg = json.loads (msg) assert msg[' E Venttype '] = = ' Check_create_suite_url ' assert msg[' Random '] = = ' LPIDSNLF ' assert suite_key = = ' Suite4xxxxxxxxxxxxxxx ' 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_signat Ure (self): Assert crypto.check_signature (Encrypt_text, timestamp, nonce, signature) def test_sign (self): msg = Cryp To.encrypt (' Hello World ') Actual_sig, actual_time, actual_nonce = crypto.sign (msg) assert True
Finally, put out the source code address of the project, hoping to some exchanges.