使用RSA函数加密字符串时的错误

问题描述 投票:0回答:0

我是加密新手,我正在尝试使用 RSA 函数加密字符串,并将公钥保存在 pubkey.pem 中。 运行以下 Python 脚本后

import rsa

# Load the public key
with open('pubkey.pem', 'rb') as key_file:
    key_data = key_file.read()
public_key = rsa.PublicKey.load_pkcs1(key_data)

# Encrypt the string using the public key
   message = b"Abiodun"
   encrypted_message = rsa.encrypt(message, public_key)

 # Print the encrypted message
  print(encrypted_message)

我收到这个错误

 raise ValueError('No PEM start marker "%r" found' % pem_start)
 ValueError: No PEM start marker "b'-----BEGIN RSA PUBLIC KEY-----'" found

不确定我做错了什么或如何解决它。公钥似乎是在正确的结构和开始

 BEGIN PUBLIC KEY
encryption rsa public-key-encryption
© www.soinside.com 2019 - 2024. All rights reserved.