serialization.BestAvailableEncryption(b'mypassword') 在 python 密码库中使用哪种加密算法?

which encryption algorithm do serialization.BestAvailableEncryption(b'mypassword') use in python cryptography lib?

我找到了这个代码片段,这里是将 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')
)

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

在 OpenSSL 后端(似乎是唯一的后端)中,选择了最好的加密 here,目前它选择了 'aes-256-cbc' 密码。这可能会在未来的版本中改变。将选择留给实施是 BestAvailableEncryption class.

的原因