使用 CryptoKit 进行密码散列
Password hashing using CryptoKit
我正在使用 (CryptoKit) 使用 AES-GCM 来加密一些数据并对其进行身份验证。
但是,我想知道如何从纯文本密码生成 AES-GCM 密钥。通常,您会为此使用 KDF
函数,例如 PBKDF2.
在 CryptoKit
中,有一个 HKDF
class 可以满足我的要求:https://developer.apple.com/documentation/cryptokit/hkdf
但是,我想知道 DeriveKey 函数使用什么 KDF 算法。它使用 PBKDF2 吗?它使用bcrypt
吗?如果是这样,我如何指定设置,或者设置是自动确定的?
HKDF 在 RFC5869 中定义。它旨在从一些加密安全的“keying material”(IKM)生成密钥。它不适用于扩展人工生成的密码。正如在 HKDF 的第 4 节应用中所讨论的:
On the other hand, it is anticipated that some applications will not
be able to use HKDF "as-is" due to specific operational requirements,
or will be able to use it but without the full benefits of the
scheme. One significant example is the derivation of cryptographic
keys from a source of low entropy, such as a user's password. The
extract step in HKDF can concentrate existing entropy but cannot
amplify entropy. In the case of password-based KDFs, a main goal is
to slow down dictionary attacks using two ingredients: a salt value,
and the intentional slowing of the key derivation computation. HKDF
naturally accommodates the use of salt; however, a slowing down
mechanism is not part of this specification. Applications interested
in a password-based KDF should consider whether, for example, [PKCS5]
meets their needs better than HKDF.
我认为 CryptoKit 不提供任何类型的 PBKDF(PBKDF2、scrypt、bcrypt、argon2)。这是一个非常有限的框架(我还没有找到它有用的情况)。您可能需要为此继续使用 CommonCrypto,或者自己实现它(或者使用像 CryptoSwift 这样的东西,我相信它实现了几个)。
我正在使用 (CryptoKit) 使用 AES-GCM 来加密一些数据并对其进行身份验证。
但是,我想知道如何从纯文本密码生成 AES-GCM 密钥。通常,您会为此使用 KDF
函数,例如 PBKDF2.
在 CryptoKit
中,有一个 HKDF
class 可以满足我的要求:https://developer.apple.com/documentation/cryptokit/hkdf
但是,我想知道 DeriveKey 函数使用什么 KDF 算法。它使用 PBKDF2 吗?它使用bcrypt
吗?如果是这样,我如何指定设置,或者设置是自动确定的?
HKDF 在 RFC5869 中定义。它旨在从一些加密安全的“keying material”(IKM)生成密钥。它不适用于扩展人工生成的密码。正如在 HKDF 的第 4 节应用中所讨论的:
On the other hand, it is anticipated that some applications will not be able to use HKDF "as-is" due to specific operational requirements, or will be able to use it but without the full benefits of the scheme. One significant example is the derivation of cryptographic keys from a source of low entropy, such as a user's password. The extract step in HKDF can concentrate existing entropy but cannot amplify entropy. In the case of password-based KDFs, a main goal is to slow down dictionary attacks using two ingredients: a salt value, and the intentional slowing of the key derivation computation. HKDF naturally accommodates the use of salt; however, a slowing down mechanism is not part of this specification. Applications interested in a password-based KDF should consider whether, for example, [PKCS5] meets their needs better than HKDF.
我认为 CryptoKit 不提供任何类型的 PBKDF(PBKDF2、scrypt、bcrypt、argon2)。这是一个非常有限的框架(我还没有找到它有用的情况)。您可能需要为此继续使用 CommonCrypto,或者自己实现它(或者使用像 CryptoSwift 这样的东西,我相信它实现了几个)。