当前位置:网站首页>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’
边栏推荐
- MySQL common commands for viewing database performance
- 港伦敦金行情走势图所隐藏的信息
- An idea plug-in that automatically generates unit tests, which improves the development efficiency by more than 70%!
- 读取pdf图片并识别内容
- Interface automation framework scaffold - use reflection mechanism to realize the unified initiator of the interface
- Who knows if it is safe to open an account with CSC securities
- etf持仓如何影响现货金价?
- Realization of a springboard machine
- ruoyi集成积木报表(nice)
- Katalon当中的output使用方法
猜你喜欢

MarkDown——基本使用语法

sqlcmd 连接数据库报错

【NLP】今年高考英语AI得分134,复旦武大校友这项研究有点意思

An idea plug-in that automatically generates unit tests, which improves the development efficiency by more than 70%!

MySQL cannot be opened. Flash back

Realize an air conditioner with compose to bring you cool in summer

Discard Tkinter! Simple configuration to quickly generate cool GUI!

How to distinguish and define DQL, DML, DDL and DCL in SQL

DlhSoft Kanban Library for WPF

Interface automation framework scaffold - use reflection mechanism to realize the unified initiator of the interface
随机推荐
[200 opencv routines] 213 Draw circle
Information hidden in the trend chart of Hong Kong London gold market
广州海关支持保障食品、农产品和中药材等民生物资稳定供港
appliedzkp zkevm(9)中的Bytecode Proof
Guangzhou Customs supports the stable supply of food, agricultural products, traditional Chinese medicine and other civilian and biological resources to Hong Kong
接口自动化框架脚手架-参数化工具的实现
[unity] built in rendering pipeline to URP
【monkey】monkey测试入门
Generate token
How to use K-line diagram for technical analysis
关于FTP的协议了解
Ribbon核心源码解析
2022吴恩达机器学习specialization Week 2 practice lab: Linear regression
Why does istio use spirit for identity authentication?
MarkDown——基本使用语法
Crawler small operation
Installing MySQL database (CentOS) in Linux source code
Resolution: overview of decentralized hosting solution
How to distinguish and define DQL, DML, DDL and DCL in SQL
如何利用k线图做技术分析