当前位置:网站首页>JSON module, hashlib, Base64
JSON module, hashlib, Base64
2022-06-28 10:36:00 【0&1 * 1】
One 、JSON modular
1) brief introduction
json Official website :https://www.json.org/
2) characteristic
Lightweight text data exchange format
Easy for human to read and write , At the same time, it is also easy for machine analysis and generation
Web The most ideal data exchange format in the world
Two 、 Front and back end data exchange
1) brief introduction
At present, the interactive use of end-to-end data before and after Internet development is basically json
3、 ... and 、JSON Rule of grammar
1) grammar
1. Data consists of key value pairs
2. Key value pairs are separated by commas
3. Save objects in braces
4. Save the array in square brackets
2) matters needing attention
1. String must be in double quotes ( namely :””) To include
2. The value can be a string 、 Numbers 、true、false、null、 list , Or a dictionary
3.[ Failed to transfer the external chain picture (img-9ofCycMM-1566960551058)(C:\Users\Administrator\Desktop\Data\Python_note\work.md\photo\1564532346252.png)]
3)JSON modular API
1.json.dumps(obj take python Data into json
Tips : ndent Achieve indent ,ensure_ascii Whether to use ascii analysis
2.json.loads(s) take json Data to python The data of
3.json.dump(obj, fp) Convert to json And save it to a file
4.json.load(fp) Read from file json, And into python data
Four 、hashlib modular
1) Introduction to data security
2) Concept
1. Symmetric encryption : Data encryption and decryption use the same key
2. Asymmetric encryption : Two different keys are used for encryption and decryption , Public keys are used to encrypt data , The private key is used to decrypt data
3. One way encryption : Only data can be encrypted , And not decrypt the data
3)HASH
4) characteristic
1. Irreversible : The original data cannot be restored according to the hash value
2. Fixed length output : No matter how long the original data is entered , The result is the same length
3. Resistance to change : Small changes in input , Even if there is only one character , It's going to cause a huge change in the outcome
4. Strong collision : It's hard to find two different pieces of data , Make them produce hash Value consistent , Next to impossible
5)hashlib modular API
1.Hashlib The module provides a number of hash Algorithm , There are mainly :
1.md5
2.SHA series :sha1, sha224, sha256, sha384, sha512
[ Failed to transfer the external chain picture (img-Dw7PLeUm-1566960551059)(C:\Users\Administrator\Desktop\Data\Python_note\work.md\photo\1564533123195.png)]
import hashlib
res = hashlib.new('md5', ' Naughty bag '.encode())
print(res) # <md5 HASH object @ 0x7fa67c687580>
print(res.digest()) # b'\x1f(\xa5\xb8v\xbf\x96\x10\x01\xc8a\xcb\x86=\xb9m'
print(res.hexdigest()) # 1f28a5b876bf961001c861cb863db96d
res = hashlib.sha256(' Naughty bag '.encode())
print(res) # <sha256 HASH object @ 0x7fce6efe9508>
print(res.hexdigest()) # b38d80a1442acd6fc7e5254dbc610a84200c956ffff6d80d5f846ce3f8948b62
# update: Don't write the value first , When you need to update once , It can be used multiple times
res = hashlib.sha1()
res.update(' spirit '.encode())
print(res.hexdigest()) # 6ff8f715acf0e19d02f416b34aa6cfb0fb521f70
res.update(' Que Linguo '.encode())
print(res.hexdigest()) # ddd2186e6d3d6be4bf9d01c68280b74483ae3858
"""
register : Original account number + The original password ---->md5 encryption ----> Save the encrypted string
Sign in : Original account number + The original password ---->md5 encryption ----> To the background , Verify whether the encrypted strings are equal
"""
#### 5、 ... and 、base64 modular
##### 1) brief introduction
[ Failed to transfer the external chain picture (img-ri8SuslM-1566960551060)(C:\Users\Administrator\Desktop\Data\Python_note\work.md\photo\1564533372155.png)]
##### 2) characteristic
1. Used to convert non ASCII The character data is converted to ASCII A method of characters
2. Often used to correct URL The coding
3. You can convert non printable binary data into printable strings
##### 3)base64 modular API
1.Base64 The encoded data may contain + / Two symbols , If the encoded data is used for URL Or the system path of the file ,
May lead to Bug, therefore base The module provides special coding url Methods
2.[ Failed to transfer the external chain picture (img-WBjvD9DO-1566960551060)(C:\Users\Administrator\Desktop\Data\Python_note\work.md\photo\1564533502035.png)]
##### 4) Encode and decode strings
[ Failed to transfer the external chain picture (img-O7DneYvy-1566960551061)(C:\Users\Administrator\Desktop\Data\Python_note\work.md\photo\1564533561196.png)]
##### 5) Yes URL Encoding and decoding
[ Failed to transfer the external chain picture (img-CzobMz0w-1566960551061)(C:\Users\Administrator\Desktop\Data\Python_note\work.md\photo\1564533605060.png)]
import base64
data = ‘ Hello, Tanzhou ’ # 1 Chinese is three bytes ,base64 Is three bytes to 4 Bytes
res = base64.b64encode(data.encode())
print(res) # b’5L2g5aW95r2t5bee’
The number of bytes is not 3 Multiple , Less bytes are used = completion
data = ‘hello world’ # 11 Bytes
res = base64.b64encode(data.encode())
print(res) # b’aGVsbG8gd29ybGQ=’
data = ‘hello worl’ # 10 Bytes
res = base64.b64encode(data.encode())
print(res) # b’aGVsbG8gd29ybA==’
# If the encoded data is used for url Or the path of the file , choice base64.urlsafe_b64encode() Way code
data = ‘hello world Hello, Tanzhou I am me , Different fireworks ’
res = base64.b64encode(data.encode())
print(res)
res = base64.urlsafe_b64encode(data.encode())
print(res) # / become _,+ become -
# decode
data = ‘ Hello, Tanzhou ’ # 1 Chinese is three bytes ,base64 Is three bytes to 4 Bytes
res = base64.b64encode(data.encode())
print(res) # b’5L2g5aW95r2t5bee’
print(base64.b64decode(res).decode()) # b’\xe4\xbd\xa0\xe5\xa5\xbd\xe6\xbd\xad\xe5\xb7\x9e’
边栏推荐
- Cisco * VRF(虚拟路由转发表)
- 一文读懂 12种卷积方法(含1x1卷积、转置卷积和深度可分离卷积等)
- Who knows if it is safe to open an account with CSC securities
- Ideal interface automation project
- Bytecode proof in appliedzkp zkevm (9)
- 第五章 树和二叉树
- To enhance the function of jupyter notebook, here are four tips
- Fabric. How to use js brush?
- Ribbon core source code analysis
- [Unity][ECS]学习笔记(二)
猜你喜欢

Katalon当中的output使用方法

港伦敦金行情走势图所隐藏的信息

fastposter v2.8.4 发布 电商海报生成器

Why does istio use spirit for identity authentication?

Interface automation framework scaffold - use reflection mechanism to realize the unified initiator of the interface
![[200 opencv routines] 213 Draw circle](/img/8d/a771ea7008f84ae3a3cf41507448ec.png)
[200 opencv routines] 213 Draw circle

Ruoyi integrated building block report (NICE)

第六天 脚本与动画系统

增强 Jupyter Notebook 的功能,这里有四个妙招

fastposter v2.8.4 发布 电商海报生成器
随机推荐
工控安全之勒索病毒篇
Transactions proof in appliedzkp zkevm (10)
Who knows if it is safe to open an account with CSC securities
appliedzkp zkevm(9)中的Bytecode Proof
第六天 脚本与动画系统
Understand 12 convolution methods (including 1x1 convolution, transpose convolution and deep separable convolution)
Install using snap in opencloudos NET 6
【LeetCode每日一题】【2021/12/19】997. 找到小镇的法官
AQS understanding
Starting from full power to accelerate brand renewal, Chang'an electric and electrification products sound the "assembly number"
Mysql通用二进制安装方式
无线通信模块定点传输-点对多点的具体传输应用
Katalon框架测试一个web页面操作实例代码
学习机器学习的最佳路径是什么
接口自动化框架脚手架-利用反射机制实现接口统一发起端
【NLP】今年高考英语AI得分134,复旦武大校友这项研究有点意思
建立自己的网站(11)
Minimum stack < difficulty coefficient >
读取pdf文字和excel写入操作
DataEase安装升级