Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create PBKDF2 key on iOS device

I need to create a PBKDF2 key to use in my AES encryption routine in my iPhone Xcode application. I have seen references to using OpenSSL to do this, but not found specific references to what module within OpenSSL to call.

I have scanned various OpenSSL .h files searching for a means to make this call, but have so far been unsuccessful.

The key I will be using is 5-digits, Salt is 12 characters, Iterations is 1000, and I need a 128-bit generated key.

like image 799
Steve Reed Sr Avatar asked Apr 03 '11 00:04

Steve Reed Sr


People also ask

How many iterations for PBKDF2?

There are 100,000 iterations, or functions, of PBKDF2 in the current version of 1Password. This means anyone who tries to guess an account password needs to perform the same calculations.

How does PBKDF2 work?

PBKDF2 applies a pseudorandom function, such as hash-based message authentication code (HMAC), to the input password or passphrase along with a salt value and repeats the process many times to produce a derived key, which can then be used as a cryptographic key in subsequent operations.

What is PBKDF2 in cyber security?

PBKDF2 is a simple cryptographic key derivation function, which is resistant to dictionary attacks and rainbow table attacks. It is based on iteratively deriving HMAC many times with some padding. The PBKDF2 algorithm is described in the Internet standard RFC 2898 (PKCS #5).


1 Answers

You can use the PKCS5_PBKDF2_HMAC_SHA1() function in openssl/evp.h. Divining how to use the function is pretty easy from the declaration:

int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
               const unsigned char *salt, int saltlen, int iter,
               int keylen, unsigned char *out);
like image 180
caf Avatar answered Sep 30 '22 21:09

caf