gpt4 book ai didi

python - 无法使用 python3 反序列化关键数据

转载 作者:行者123 更新时间:2023-12-04 00:47:31 25 4
gpt4 key购买 nike

我正在尝试将公钥发送到使用 python 构建的服务器,但在调用 load_pem_public_key 时出现以下错误

key = serialization.load_pem_public_key(pem_data,backend=default_backend()) 

File "/usr/local/lib/python3.5/dist-packages/cryptography/hazmat/primitives/serialization.py", line 24, in load_pem_public_key
return backend.load_pem_public_key(data)
File "/usr/local/lib/python3.5/dist-packages/cryptography/hazmat/backends/openssl/backend.py", line 1040, in load_pem_public_key
self._handle_key_loading_error()
File "/usr/local/lib/python3.5/dist-packages/cryptography/hazmat/backends/openssl/backend.py", line 1291, in _handle_key_loading_error
raise ValueError("Could not deserialize key data.") ValueError: Could not deserialize key data.
我的功能是这样的:
pem_data = request.args.get('public_key').encode()
key = serialization.load_pem_public_key(pem_data,backend=default_backend())
pem_data looks喜欢(PEM 格式)
-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxt/G jhPU1Pt 0q68jEu\n9aXUohWo46G38t6KV1WQBbGpn28Uz9JvthITARtSW Q/6Sc3MNQdjDyUrdL64Mmq\nPTWVVOS8wSB ZayiZq48isoPQh4TPtv3exFNMaI2/339laoVX3aFjF7zxcyKgTVk\ng4Dm2ny9iPIEN3BTGn3FxD9lz3LyxVUd2pAV29wdI06TdDs8xI1P1xp8/gDJxZH3\nUroRAGphXTnfxn Aq5lAMesGG6HnO0/e KBLGeKFEIkIaH31555yQ3uBptl 3c9m\nkTOeBzMlvxX0rAVsZAXC8k1xoD28glUXQvcewq DqmsUNAVOLfHFhaNP6Lztjjuz\nMQIDAQAB\n-----END PUBLIC KEY-----\n
感谢您的帮助 !

最佳答案

这似乎是无效的。我无法使用 openssl 加载它.
它包含空格。

细节:

$ cat pubkey.pem
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxt/G jhPU1Pt 0q68jEu
9aXUohWo46G38t6KV1WQBbGpn28Uz9JvthITARtSW Q/6Sc3MNQdjDyUrdL64Mmq
PTWVVOS8wSB ZayiZq48isoPQh4TPtv3exFNMaI2/339laoVX3aFjF7zxcyKgTVk
g4Dm2ny9iPIEN3BTGn3FxD9lz3LyxVUd2pAV29wdI06TdDs8xI1P1xp8/gDJxZH3
UroRAGphXTnfxn Aq5lAMesGG6HnO0/e KBLGeKFEIkIaH31555yQ3uBptl 3c9m
kTOeBzMlvxX0rAVsZAXC8k1xoD28glUXQvcewq DqmsUNAVOLfHFhaNP6Lztjjuz
MQIDAQAB
-----END PUBLIC KEY-----


$ openssl pkey -inform PEM -pubin -in pubkey.pem -noout
unable to load Public Key
140571453707392:error:0D07209B:asn1 encoding routines:ASN1_get_object:too long:../crypto/asn1/asn1_lib.c:91:
140571453707392:error:0D068066:asn1 encoding routines:asn1_check_tlen:bad object header:../crypto/asn1/tasn_dec.c:1118:
140571453707392:error:0D07803A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:../crypto/asn1/tasn_dec.c:290:Type=X509_PUBKEY
140571453707392:error:0906700D:PEM routines:PEM_ASN1_read_bio:ASN1 lib:../crypto/pem/pem_oth.c:33:

关于python - 无法使用 python3 反序列化关键数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49909957/

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