PKCS12_ADD_SAFE(3ossl)
π PKCS12_ADD_SAFE π
okay bestie, pull up a chair, we're doing pkcs12_add_safe β that's the page from the OpenSSL manual, section 3ossl π. It's all about building PKCS#12 structures and stuffing objects into them. Sounds scary, is actually just legos but for crypto. Let's go β¨
πΈ NAME πΈ
PKCS12_add_safe, PKCS12_add_safe_ex, PKCS12_add_safes, PKCS12_add_safes_ex β Create and add objects to a PKCS#12 structure π«Ά
π¦ SYNOPSIS π¦
#include <openssl/pkcs12.h>
int PKCS12_add_safe(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags,
int safe_nid, int iter, const char *pass);
int PKCS12_add_safe_ex(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags,
int safe_nid, int iter, const char *pass,
OSSL_LIB_CTX *ctx, const char *propq);
PKCS12 *PKCS12_add_safes(STACK_OF(PKCS7) *safes, int p7_nid);
PKCS12 *PKCS12_add_safes_ex(STACK_OF(PKCS7) *safes, int p7_nid,
OSSL_LIB_CTX *ctx, const char *propq);
π DESCRIPTION π
PKCS12_add_safe() makes a brand-new PKCS7 contentInfo, drops the PKCS12_SAFEBAGs you handed it inside, and adds the whole thing to a set of PKCS7 contentInfos. And what kind of contentInfo you get? That's fully decided by safe_nid, bestie:
- If
safe_nidis-1, you get a plainPKCS7data contentInfo. Simple. Clean. No encryption, no drama π - If
safe_nidis a valid PBE algorithm NID, you get aPKCS7encryptedData contentInfo β¨. The algorithm usespassas the passphrase anditeras the iteration count. And ifiteris zero? Not me forgetting the iterations β the default value for the iteration count is2048and it gets used instead π«Ά - If
safe_nidis0, you get aPKCS7encryptedData contentInfo too, but this time with a default encryption algorithm. Currently that'sNID_pbe_WithSHA1And3_Key_TripleDES_CBCπ
PKCS12_add_safe_ex() is literally the same as PKCS12_add_safe(), except it lets a library context ctx and a property query propq get involved in picking which algorithm implementations get used π
PKCS12_add_safes() builds a PKCS12 structure that holds the set of PKCS7 contentInfos you gave it. The safes get enclosed first inside a PKCS7 contentInfo of type p7_nid. And rn the only supported type is NID_pkcs7_data β that's it, that's the whole menu π
PKCS12_add_safes_ex() is literally the same as PKCS12_add_safes(), except again: library context ctx and property query propq come along to select algorithm implementations πΈ
π NOTES π
okay heads up, this one matters: PKCS12_add_safe() makes assumptions regarding the encoding of the given pass phrase. Like, it just assumes. Go read passphrase-encoding(7) for the whole story, iykyk π
π RETURN VALUES π
PKCS12_add_safe()returns1meaning slay (success), or0meaning nope (failure) πPKCS12_add_safes()returns a validPKCS12structure, orNULLif an error happened π
π CONFORMING TO π
IETF RFC 7292 (<https://tools.ietf.org/html/rfc7292>) β yes, we're standards girlies π
π SEE ALSO π
β HISTORY β
PKCS12_add_safe_ex() and PKCS12_add_safes_ex() were added in OpenSSL 3.0 β the _ex girlies are the new kids, periodt β¨
π COPYRIGHT π
Copyright 2020-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>.
and that's the whole page, bestie!! π¦β¨ this was OpenSSL 3.5.9, dated 2026-09-29, and it's the PKCS12_ADD_SAFE(3ossl) manual β go forth and encrypt your contentInfos responsibly, ily πππ
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms