libnitrokey 3.8.0
Loading...
Searching...
No Matches
libnitrokey

libnitrokey provides access to Nitrokey Pro and Nitrokey Storage devices. This documentation describes libnitrokey's C API. For a list of the available functions, see the NK_C_API.h file.

Example

#include <stdio.h>
#include <stdlib.h>
#include <libnitrokey/NK_C_API.h>
int main(void)
{
if (NK_login_auto() != 1) {
fprintf(stderr, "No Nitrokey found.\n");
return 1;
}
printf("Connected to ");
switch (model) {
case NK_PRO:
printf("a Nitrokey Pro");
break;
case NK_STORAGE:
printf("a Nitrokey Storage");
break;
case NK_LIBREM:
printf("a Librem Key");
break;
default:
printf("an unsupported Nitrokey");
break;
}
char* serial_number = NK_device_serial_number();
if (serial_number)
printf(" with serial number %s\n", serial_number);
else
printf(" -- could not query serial number!\n");
free(serial_number);
return 0;
}
NK_C_API char * NK_device_serial_number()
Return the device's serial number string in hex.
NK_C_API int NK_login_auto()
Connect to first available device, starting checking from Pro 1st to Storage 2nd.
NK_C_API enum NK_device_model NK_get_device_model()
Query the model of the connected device.
NK_C_API int NK_logout()
Disconnect from the device.
NK_device_model
The Nitrokey device models supported by the API.
Definition NK_C_API.h:105
@ NK_PRO
Nitrokey Pro.
Definition NK_C_API.h:113
@ NK_LIBREM
Librem Key.
Definition NK_C_API.h:121
@ NK_STORAGE
Nitrokey Storage.
Definition NK_C_API.h:117