首页 > 编程知识 正文

python模块介绍大全,sm爆乳hash

时间:2023-05-04 05:41:49 阅读:23974 作者:1859

本文主要详细介绍如何使用Python hashlib模块的实例。 示例代码详细介绍,对大家的学习和工作有一定的参考学习价值,有需要的朋友可以参考

hashlib模块的主要作用:

使用常见的加密算法(如MD5、SHA1等)保护邮件的安全。

1、查看可用算法

hashlib_algorithms.py

#! /usr/温柔的白云/env python

#-* -编码: utf-8-* -

import hashlib

#始终可用的算法

print ()始终可用的算法:(}.format ) sorted (hash lib.algorithms _ guaranteed ) )

必须与print () OpenSSL中可用的算法:(}.format ) sorted (hash lib.algorithms _ available ) )结合使用)

执行效果

[ root @ mnt ] # python3hash lib _ algorithms.py

始终可用的算法: ['blake2b '、' blake2s '、' md5 '、' sha1 '、' sha224 '、' sha256 '、' sha384 '、' sha3_224 '和]

OpenSSL中可用的算法: ['DSA '、' DSA-SHA '、' MD4 '、' MD5 '、' RIPEMD160 '、' SHA '、' SHA1'、' SHA224 ', '需要与SHA256结合使用的DSA加密、dsaWithSHA、ecdsa-with-SHA1、md4、md5、ripemd160和sha

2、md5加密算法(无加盐) ) ) ) ) )。

hashlib_md5.py

#! /usr/温柔的白云/env python

#-* -编码: utf-8-* -

import hashlib

md5_obj=hashlib.md5 (

MD5_obj.update(123456 ).encode (utf-8 ) )

print(MD5_obj.hexdigest ) )

执行效果

[ root @ mnt ] # python3hash lib _ MD5.py

e 10a DC 3949 ba 59 abb e56 e 057 f 20 f 883 e

3、md5加密算法(加盐) )。

hashlib_md5_salt.py

#! /usr/温柔的白云/env python

#-* -编码: utf-8-* -

import hashlib

salt='1234 '

MD5 _ obj=hash lib.MD5 (salt.encode (' utf-8 ' ) )

MD5_obj.update(123456 ).encode (utf-8 ) )

print(MD5_obj.hexdigest ) )

执行效果

[ root @ mnt ] # python3hash lib _ MD5 _ salt.py

b 38 e2BF 274239 ff 5d2b 45 ee9AE 099 c 9

4、sha1加密算法

hashlib_sha1.py

#! /usr/温柔的白云/env python

#-* -编码: utf-8-* -

import hashlib

sha1_obj=hashlib.sha1 (

sha1_obj.update(123456 ).encode (utf-8 ) )

print(sha1_obj.hexdigest ) )

hashlib_sha1.py

执行效果

[ root @ mnt ] # python3hash lib _ sha1.py

7 c4a 8d 09 ca 3762 af 61 e 59520943 DC 26494 f 8941 b

5、使用加密算法名称动态加密(即hashlib.new(‘)“算法名称”) )

hashlib_new.py

#! /usr/温柔的白云/env python

#-* -编码: utf-8-* -

import hashlib

导入警报

lorem='Hello World '

parser=arg parse.argument parser (hashlibdemo ) )。

parser.add_argument (

' hash_name ',

choices=hash lib.algorithms _ available,

help='请输入hash lib的名称'

parser.add_argument (

'数据',

nargs='?' ,

default=lorem,

help=“请输入要加密的数据”

args=parser.parse_args (

h=hashlib.new(Args.hash_name ) )。

h .更新(args.data.encode ) (utf-8 ) )

打印(h.hex digest ) )

执行效果

[ root @ mnt ] # python3hash lib _ new.pymd 5123456

e 10a DC 3949 ba 59 abb e56 e 057 f 20 f 883 e

[ root @ mnt ] # python3hash lib _ new.pysha 1123456

7 c4a 8d 09 ca 3762 af 61 e 59520943 DC 26494 f 8941 b

[ root @ mnt ] # python3hash lib _ new.pysha 256123456

8d 969 ee F6 ecad 3c 29 a3 a 629280 e 686 cf0C3 F5 D5 a86 aff 3c a 12020 c 923 ADC6c 92

[ root @ mnt ] # python3hash lib _ new.pysha 512123456

ba 3253876 aed 6b c 22 D4 a6 ff 53 d 8406 c6ad 864195 ed 144 ab 5c 87621 b6c 233 b 548 baeae 6956 df 346 e c8c 17 F5 e a10 f35 ee 3c BC 514797 ed7DDD 3145464 e2a0Bab 4456

6、大文件切片md5加密算法

hashlib_update.py

#! /usr/温柔的白云/env python

#-* -编码: utf-8-* -

import hashlib

content=' ' ' loremipsumdolorsitamet,consectetur adipisicing

elit,seddoeiusmodtemporincididuntutlaboreetdoloremagna

aliqua. Ut enim ad minim veniam,quis nostrud exercitation

ullamcolaborisnisiutaliquipexeacommodoconsequat.duis

auteiruredolorinreprehenderitinvoluptatevelitessecillum

doloreeufugiatnullapariatur.excepteursintoccaecat

cupidatat non proident,sunt in culpa qui officia deserunt

mollit anim id est laborum.' '

#一次性密码:缺点文件较大时,加载到内存中会导致内存溢出

h=hashlib.md5 ()

h.update (内容. encode ) (utf-8 ) ) )

all_at_once=h.hexdigest (

#使用生成器进行切片加密有助于加密大型文件

efchunkize(size,text ) :

开始=0

wilestartlen (文本) :

chuck=text [ start : startsize ]

叶尔德车克

start =size

返回

#1逐行加密

h=hashlib.md5 ()

forchunkinchunkize(64,content.encode ) (utf-8 ) ) ) :

是h.update(chunk )

line_by_line=h.hexdigest (

print (初级加密结果: )、all_at_once ) ) )。

print(1 (一行一行加密结果: )、line_by_line () ) ) ) ) ) )。

执行效果

[ root @ mnt ] # python3hash lib _ update.py

初级加密结果:3 f2f d2c 9e 25 d 60 FB 0f a5d 593 b 802 b 7a 8

一行加密结果:3 f2f d2c 9e 25 d 60 FB 0f a5d 593 b 802 b 7a 8

以上就是这篇文章的全部。 希望对大家的学习有帮助。 另外,请支持python博客。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。