Skip to content

PK11SymKey

Endi S. Dewata edited this page Jul 11, 2022 · 6 revisions

Data Structure

/* Symetric Key structure. Reference Counted */
struct PK11SymKeyStr {
    CK_MECHANISM_TYPE type;    /* type of operation this key was created for*/
    CK_OBJECT_HANDLE objectID; /* object id of this key in the slot */
    PK11SlotInfo *slot;        /* Slot this key is loaded into */
    void *cx;                  /* window context in case we need to loggin */
    PK11SymKey *next;
    PRBool owner;
    SECItem data; /* raw key data if available */
    CK_SESSION_HANDLE session;
    PRBool sessionOwner;
    PRInt32 refCount;          /* number of references to this key */
    int size;                  /* key size in bytes */
    PK11Origin origin;         /* where this key came from
                                * (see def in secmodt.h) */
    PK11SymKey *parent;        /* potential owner key of the session */
    PRUint16 series;           /* break up the slot info into various groups
                                * of inserted tokens so that keys and certs
                                * can be invalidated */
    void *userData;            /* random data the application can attach to
                                * this key */
    PK11FreeDataFunc freeFunc; /* function to free the user data */
};

typedef struct PK11SymKeyStr PK11SymKey;              /* defined in secmodti.h */

Creating Symmetric Key

PK11SlotInfo *slot;
CK_MECHANISM_TYPE mech;
jint strength;
jint opFlags;
PK11AttrFlags attrFlags;
PK11SymKey *symmetricKey;

symmetricKey = PK11_TokenKeyGenWithFlags(
    slot,
    mech,
    NULL /*param*/,
    strength/8 /*in bytes*/,
    NULL /*keyid*/,
    opFlags,
    attrFlags,
    NULL /*wincx*/);

Getting Nickname

PK11SymKey *key;
char *nickname;

nickname = PK11_GetSymKeyNickname(key);

Methods

  • PK11SymKey* PK11_ListFixedKeysInSlot(PK11SlotInfo *slot, char *nickname, void *wincx)