gpt4 book ai didi

来自字符串的 Python M2Crypto load_pub_key

转载 作者:太空宇宙 更新时间:2023-11-04 03:10:21 24 4
gpt4 key购买 nike

我如何从字符串中加载_pub_key。

pub_key1 = M2Crypto.RSA.load_pub_key('public.pem')
f = open('public.pem', 'rb')
bio = M2Crypto.BIO.MemoryBuffer(f.read())
pub_key2 = M2Crypto.RSA.load_pub_key_bio(bio)
print pub_key1 == pub_key2

false

最佳答案

打印 pub_key1 == pub_key2 -> false,但是:

PUBKEY_TEMPLATE = "-----BEGIN PUBLIC KEY-----\n{}\n-----END PUBLIC KEY-----"
pub_key1 = M2Crypto.RSA.load_pub_key('public.pem')
bio = M2Crypto.BIO.MemoryBuffer(PUBKEY_TEMPLATE.format('<string with pub key>'.strip()))
pub_key2 = M2Crypto.RSA.load_pub_key_bio(bio)
CipherText1 = pub_key1.public_encrypt("This is a secret", M2Crypto.RSA.pkcs1_oaep_padding)
CipherText2 = pub_key2.public_encrypt("This is a secret", M2Crypto.RSA.pkcs1_oaep_padding)
RSA = M2Crypto.RSA.load_key('private.pem')
Text1 = RSA.private_decrypt(CipherText1, M2Crypto.RSA.pkcs1_oaep_padding)
Text2 = RSA.private_decrypt(CipherText2, M2Crypto.RSA.pkcs1_oaep_padding)
print Text1
print Text2


This is a secret
This is a secret

关于来自字符串的 Python M2Crypto load_pub_key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38225131/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com