【问题标题】:which encryption algorithm do serialization.BestAvailableEncryption(b'mypassword') use in python cryptography lib?在 python 加密库中使用哪种加密算法 serialization.BestAvailableEncryption(b'mypassword')?
【发布时间】:2020-07-24 17:58:42
【问题描述】:

我找到了这段代码 sn-p,这里它是将 RSA 私钥序列化为加密的密文。我想知道这段代码serialization.BestAvailableEncryption(b'mypassword') 中的哪个算法将用于这样做。

from cryptography.hazmat.primitives import serialization
pem = private_key.private_bytes(
      encoding=serialization.Encoding.PEM,
      format=serialization.PrivateFormat.PKCS8,
      encryption_algorithm=serialization.BestAvailableEncryption(b'mypassword')
)

【问题讨论】:

  • 我看到该类被代码解释的唯一地方是here,其中openssl 后端选择aes-256-cbc 作为要使用的密码。我不确定我是否了解加密库的结构,以确保这就是您想要的答案。
  • @Blckknght 感谢您的评论。是的,我认为这是正确的答案。

标签: python python-cryptography


【解决方案1】:

这取决于private_key 对象的实现。 BestAvailableEncryption 只是表示您没有特定的偏好,并希望库为您选择密钥的加密类型。

在 OpenSSL 后端(似乎是唯一一个)中,选择了最佳加密 here,目前它选择了 'aes-256-cbc' 密码。这可能会在未来的版本中改变。将选择留给实现是拥有BestAvailableEncryption 类的原因。

【讨论】:

    猜你喜欢
    • 2013-03-30
    • 1970-01-01
    • 2015-08-29
    • 2022-09-27
    • 1970-01-01
    • 2011-07-09
    • 1970-01-01
    • 2021-12-06
    • 1970-01-01
    相关资源
    最近更新 更多