【问题标题】:Generating public key with EC in Python [closed]在 Python 中使用 EC 生成公钥 [关闭]
【发布时间】:2020-01-07 09:45:33
【问题描述】:

我正在创建 JWT 解析器,现在我需要创建公钥。我是在 Kotlin 中实现的。但现在我必须在 Python 中创建相同的解析器。但我陷入了在 python 中创建 X.509 证书的困境。我尝试使用 cryptography 库但没有成功。 Kotlin 中的代码。感谢您的回复。

val factory = KeyFactory.getInstance("EC")
val publicSpec = X509EncodedKeySpec(Base64.getMimeDecoder().decode(key))
return factory.generatePublic(publicSpec)

【问题讨论】:

    标签: python cryptography jwt x509 python-cryptography


    【解决方案1】:

    您可能应该结合this tutorial 来生成自签名证书并用this material 替换私钥生成。

    使用 SECP384R1 的密钥生成示例:

    from cryptography.hazmat.backends import default_backend
    from cryptography.hazmat.primitives import hashes
    from cryptography.hazmat.primitives.asymmetric import ec
    key = ec.generate_private_key(
         ec.SECP384R1(), default_backend()
    )
    

    【讨论】:

    • 我试过这个库但没有成功。
    • @PatrikDendis 好吧,显示您的代码以便我们提供帮助
    • 谢谢@Lou_is,但我放弃了,我使用从 Kotlin 生成的公钥,然后粘贴到 Python。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-29
    • 1970-01-01
    • 2014-10-11
    • 1970-01-01
    • 1970-01-01
    • 2020-05-12
    • 2018-02-20
    相关资源
    最近更新 更多