2

所以我使用命令: ssh-keygen -m PKCS8 -t dsa生成以下(示例)密钥:

-----BEGIN PRIVATE KEY-----
MIIBSgIBADCCASsGByqGSM44BAEwggEeAoGBAIATtp/DhG2hDIT3DiMIctaxPn/s
FFxbXa4IIytk0b/PDBq9Kv/OeFv54h1L9iSLoNHrsx3dOR+6CyFyfnZT9s0yjpSe
uYiU6QVhX1sl24KzlpTXgu2vXlBx24vNq4adGmRROxtxjBaiAlN8va4oM0GT8hNG
sJ6uAWmFfYvqvnulAhUAtuiO7CyAzrkXcneK3qWYntor2w0CgYAYMEDqn+gjIfhx
IcZCA3eTUbuE4xAfzLwz0XSvUbaxYn9bJFmQ17F1vdnD1a4tEy7dyLj1EUNarNUF
P/T/BJdX7P4g+Fua96RuuvUkJ/gFshFBRWgyXyBsvydcZrbYhpSag8jwLo3QAuse
ulTIWyR8BRgYjmmCFIw0uNS86Kyu7wQWAhQtuXafDJ4JWDMpSPHxU+UwzbjfeA==
-----END PRIVATE KEY-----

我正在尝试使用以下代码段使用此密钥对数据进行签名:

import jwt

with open('./id_dsa', 'r') as file:
  key = file.read()
  print(key)
  token = jwt.encode({'some': 'data'}, key, algorithm='EdDSA')

但我收到此错误:

Traceback (most recent call last):
  File "./client.py", line 23, in <module>
    token = jwt.encode({'username': args.username,'publicKey': args.pubKey}, key, algorithm='EdDSA')
  File "/home/walt/angi/auth/lib/python3.8/site-packages/jwt/api_jwt.py", line 63, in encode
    return api_jws.encode(json_payload, key, algorithm, headers, json_encoder)
  File "/home/walt/angi/auth/lib/python3.8/site-packages/jwt/api_jws.py", line 114, in encode
    signature = alg_obj.sign(signing_input, key)
  File "/home/walt/angi/auth/lib/python3.8/site-packages/jwt/algorithms.py", line 578, in sign
    return key.sign(msg)
TypeError: sign() missing 1 required positional argument: 'algorithm'

我不确定我生成的密钥是否不正确或者我可能做错了什么。

4

0 回答 0