首页 > 编程知识 正文

Python编写rsa加解密算法,rsa的加密Python

时间:2023-05-05 13:54:58 阅读:149296 作者:2056

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

import rsa

#生成键

(pubkey,privkey )=RSA.Newkeys(1024 ) ) ) )。

#======================================#=============。

#场景0 )密钥保存导入

#======================================#=============。

#保存键

withopen(public.PEM,) w ) ) as f:

f.write(Pubkey.save_PKcs1 ).decode ) )

print ((========================' )

withopen('private.PEM ',' w ' ) as f:

f.write(privkey.save_PKcs1 ().decode ) )

#导入密钥

withopen(public.PEM,) r ) ) as f:

withopen('private.PEM ',' r ' ) as f:

withopenajdjj/RSA _ public _ key.PEM ',' r ' ) as f:

withopenajdjj/RSA _ private _ key.PEM ',' r ' ) as f:

“”'

加密mtdbm/p ' '

DEFRSA_encrypt(message ) :

crypto _ email _ text=RSA.encrypt (message.encode (),pubkey ) ) ) ) ) ) ) )。

return crypto_email_text

# message='这是商机:'

#print(Pubkey,'n ' ) ) ) ) ) ) ) ) ) ) ) ) )0) 0

# crypto _ email _ text=RSA.encrypt (message.encode ),pubkey ) ) ) ) ) ) ) ) ) )。

#print(crypto_email_text ) )。

text=RSA_encrypt(Helloworld ) )。

是打印(文本)

“”'

“”'

DEFRSA_decrypt(message ) :

return message_str

print('n ',消息)

“”'

“”'

crypto _ email _ text=RSA.sign (message.encode ),privkey,' SHA-1 ' ) ) ) ) ) ) ) )。

“”'

“”'

#接收命令文、密文,用公钥验证,进行身份确认

RSA.verify(message.encode )、crypto_email_text、pubkey ) ) )。

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