作者热门文章
- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Python制作钉钉加密/解密工具由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
又是很久没有写技术博客了,盖因最近都在学习知识,也没有总结出什么值得分享的内容,所以一直停笔至今。最近的工作和钉钉的开发打上了交到,官方并没有提供任何Python的SDK,于是只能全部自己写。现在我将其中实现起来相对费时间的“加密/解密/签名”部分分享出来,希望能帮助到一些人.
加密/解密的具体机制,可以参考 官方文档 .
在你的项目中安装这个扩展,可以使用: pip install dingtalk_crypto 安装.
使用方法,可以参考下面的测试代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# -*- coding: utf-8 -*-
import
json
from
dingtalk_crypto
import
DingTalkCrypto
# 这个是钉钉官方给的测试数据
# @see https://open-doc.dingtalk.com/doc2/detail.htm?treeId=175&articleId=104945&docType=1#s14
encrypt_text
=
'1a3NBxmCFwkCJvfoQ7WhJHB+iX3qHPsc9JbaDznE1i03peOk1LaOQoRz3+nlyGNhwmwJ3vDMG'
\
'+OzrHMeiZI7gTRWVdUBmfxjZ8Ej23JVYa9VrYeJ5as7XM/ZpulX8NEQis44w53h1qAgnC3PRzM7Zc'
\
'/D6Ibr0rgUathB6zRHP8PYrfgnNOS9PhSBdHlegK+AGGanfwjXuQ9+0pZcy0w9lQ=='
crypto
=
DingTalkCrypto(
'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[
'EventType'
]
=
=
'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_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
|
最后,贴出项目的 源码地址 ,希望能一些交流.
最后此篇关于Python制作钉钉加密/解密工具的文章就讲到这里了,如果你想了解更多关于Python制作钉钉加密/解密工具的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我是一名优秀的程序员,十分优秀!