PKCS12_PBE_KEYIVGEN(3SSL)
π PKCS12_PBE_KEYIVGEN β the OpenSSL 3SSL bestie guide π
okay so you're here for PKCS12_PBE_KEYIVGEN(3SSL) and honestly? iconic choice. this is the PKCS#12 password-based-encryption page, and we're gonna get through it together. grab a strawberry drink π, we move.
β¨ NAME β¨
PKCS12_PBE_keyivgen, PKCS12_PBE_keyivgen_ex, PKCS12_pbe_crypt, PKCS12_pbe_crypt_ex β PKCS#12 password based encryption π
like. that's the whole vibe. passwords + encryption + the PKCS#12 of it all.
β¨ SYNOPSIS β¨
first things first, you gotta let the compiler know:
#include <openssl/evp.h>
and then these four besties:
int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
ASN1_TYPE *param, const EVP_CIPHER *cipher,
const EVP_MD *md_type, int en_de);
int PKCS12_PBE_keyivgen_ex(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
ASN1_TYPE *param, const EVP_CIPHER *cipher,
const EVP_MD *md_type, int en_de,
OSSL_LIB_CTX *libctx, const char *propq);
unsigned char *PKCS12_pbe_crypt(const X509_ALGOR *algor,
const char *pass, int passlen,
const unsigned char *in, int inlen,
unsigned char **data, int *datalen,
int en_de);
unsigned char *PKCS12_pbe_crypt_ex(const X509_ALGOR *algor,
const char *pass, int passlen,
const unsigned char *in, int inlen,
unsigned char **data, int *datalen,
int en_de, OSSL_LIB_CTX *libctx,
const char *propq);
note how the _ex ones have libctx and propq bolted on the end. foreshadowing β¨.
β¨ DESCRIPTION β¨
π the keyivgen girls
PKCS12_PBE_keyivgen() and PKCS12_PBE_keyivgen_ex() take a password pass of length passlen, parameters param, and a message digest function md_type, and they do a key derivation according to PKCS#12. then that freshly-baked key gets used to initialise the cipher context ctx with a cipher cipher β for encryption when en_de=1, or decryption when en_de=0. that's it, that's the job π«Ά
PKCS12_PBE_keyivgen_ex() is the extra version: it also lets your app specify a library context libctx and a property query propq, so you can pick which algorithm implementations you want. very "I choose my own destiny" of it.
π the pbe_crypt girls
PKCS12_pbe_crypt() and PKCS12_pbe_crypt_ex() encrypt or decrypt a buffer, using the algorithm in algor and the password pass of length passlen. input comes from in with length inlen, and output goes into a malloc'd buffer that gets handed back in *data with length datalen. which direction it goes is decided by en_de β encryption (en_de=1) or decryption (en_de=0) π₯
PKCS12_pbe_crypt_ex() also lets the application specify a library context libctx and a property query propq to select appropriate algorithm implementations. same energy as above, no cap.
π the deets on the params (iykyk)
passβ the password used in the derivation, of lengthpasslen. it's optional, so it can legitimately beNULL. and ifpasslenis-1, the function will just compute the length ofpassusingstrlen(). convenient πsaltβ the salt used in the derivation, of lengthsaltlen. if the salt isNULL, thensaltlenmust be0. the function will not try to figure out the length of the salt, because it does not assume the salt is NUL-terminated. so no guessing games here.iterβ the iteration count, and its value should be greater than or equal to1. RFC 2898 suggests an iteration count of at least1000. anyiterless than1is treated as a single iteration. shortest possible glow-up β¨digestβ the message digest function used in the derivation.- functions ending in
_ex()take the optional parameterslibctxandpropq, which are used to select appropriate algorithm implementations.
β¨ NOTES β¨
these functions are typically used in PKCS#12 to encrypt objects. that's the whole point of them, bestie.
also, lowkey important: these functions make no assumption regarding the given password. it will simply be treated as a byte sequence. no parsing, no judgement, no vibes-checking your string. just bytes π¦
β¨ RETURN VALUES β¨
PKCS12_PBE_keyivgen(),PKCS12_PBE_keyivgen_ex()return1on success, or0on error.PKCS12_pbe_crypt()andPKCS12_pbe_crypt_ex()return a buffer containing the output, orNULLif an error occurred. π
check your returns, bestie. always.NULLand0are out here and they will humble you.
β¨ CONFORMING TO β¨
IETF RFC 7292 (<https://tools.ietf.org/html/rfc7292>) β we stay compliant, periodt. π
β¨ SEE ALSO β¨
β¨ HISTORY β¨
PKCS12_PBE_keyivgen_ex() and PKCS12_pbe_crypt_ex() were added in OpenSSL 3.0. the _ex era began π
β¨ COPYRIGHT β¨
Copyright 2014-2021 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
okay slay, that's the whole page π this was OpenSSL 4.0.3, dated 2026-09-29, and yeah we're still on PKCS12_PBE_KEYIVGEN(3SSL) around here. go encrypt something responsibly, bestie πβ¨
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms