Convert Figma logo to code with AI

OpenSC logoOpenSC

Open source smart card tools and middleware. PKCS#11/MiniDriver/Tokend

2,519
724
2,519
124

Top Related Projects

20,728

KeePassXC is a cross-platform community-driven port of the Windows application “Keepass Password Safe”.

Quick Overview

OpenSC is an open-source project that provides a set of libraries and tools for working with smart cards. It supports a wide range of smart cards and security tokens, enabling users to perform cryptographic operations, manage digital certificates, and interact with various card types using a unified interface.

Pros

  • Supports a wide range of smart cards and security tokens
  • Cross-platform compatibility (Windows, macOS, Linux)
  • Actively maintained with regular updates and security patches
  • Extensive documentation and community support

Cons

  • Steep learning curve for beginners
  • Some advanced features may require in-depth knowledge of smart card technology
  • Occasional compatibility issues with certain card types or readers

Code Examples

  1. Listing available smart card readers:
#include <stdio.h>
#include <opensc/opensc.h>

int main() {
    sc_context_t *ctx;
    sc_context_param_t ctx_param;
    
    memset(&ctx_param, 0, sizeof(ctx_param));
    sc_context_create(&ctx, &ctx_param);
    
    unsigned int i, reader_count;
    sc_reader_t *readers[SC_MAX_READERS];
    
    reader_count = sc_ctx_get_reader_count(ctx);
    for (i = 0; i < reader_count; i++) {
        printf("Reader %d: %s\n", i, sc_ctx_get_reader(ctx, i)->name);
    }
    
    sc_release_context(ctx);
    return 0;
}
  1. Reading a file from a smart card:
#include <stdio.h>
#include <opensc/opensc.h>

int main() {
    sc_context_t *ctx;
    sc_card_t *card;
    sc_path_t path;
    u8 buffer[256];
    size_t buffer_len = sizeof(buffer);
    
    sc_context_create(&ctx, NULL);
    sc_connect_card(ctx, 0, &card);
    
    sc_format_path("3F00", &path);
    sc_select_file(card, &path, NULL);
    
    sc_read_binary(card, 0, buffer, buffer_len, 0);
    
    // Process the read data
    
    sc_disconnect_card(card);
    sc_release_context(ctx);
    return 0;
}
  1. Signing data using a private key on the smart card:
#include <stdio.h>
#include <opensc/opensc.h>

int main() {
    sc_context_t *ctx;
    sc_card_t *card;
    sc_pkcs15_card_t *p15card;
    sc_pkcs15_object_t *key_obj;
    sc_pkcs15_prkey_info_t *key_info;
    u8 data_to_sign[] = "Hello, OpenSC!";
    u8 signature[256];
    size_t sig_len = sizeof(signature);
    
    sc_context_create(&ctx, NULL);
    sc_connect_card(ctx, 0, &card);
    sc_pkcs15_bind(card, &p15card);
    
    sc_pkcs15_find_prkey_by_id(p15card, &key_obj->id, &key_obj);
    key_info = (sc_pkcs15_prkey_info_t *)key_obj->data;
    
    sc_pkcs15_compute_signature(p15card, key_obj, SC_ALGORITHM_RSA_PAD_PKCS1,
                                data_to_sign, sizeof(data_to_sign),
                                signature, sig_len);
    
    // Process the signature
    
    sc_pkcs15_unbind(p15card);
    sc_disconnect_card(card);
    sc_release_context(ctx);
    return 0;
}

Getting Started

To get started with OpenSC:

  1. Install OpenSC using your package manager or build from

Competitor Comparisons

20,728

KeePassXC is a cross-platform community-driven port of the Windows application “Keepass Password Safe”.

Pros of KeePassXC

  • User-friendly graphical interface for password management
  • Cross-platform compatibility (Windows, macOS, Linux)
  • Extensive feature set including password generation and browser integration

Cons of KeePassXC

  • Limited focus on smart card and cryptographic token support
  • Less specialized for low-level cryptographic operations
  • May have a steeper learning curve for users new to password managers

Code Comparison

KeePassXC (C++):

void Database::setKey(const CompositeKey& key)
{
    m_key = key;
    m_kdf->randomize();
    m_masterSeed = QByteArray(32, '\0');
    Tools::randomize(m_masterSeed);
}

OpenSC (C):

int sc_pkcs15_create_pin(struct sc_pkcs15_card *p15card,
                         struct sc_profile *profile,
                         struct sc_pkcs15_object *pin_obj,
                         struct sc_pkcs15_auth_info *pin_info,
                         const u8 *pin, size_t pin_len,
                         const u8 *puk, size_t puk_len)
{
    // Implementation details
}

KeePassXC focuses on high-level password management functionality, while OpenSC provides low-level smart card and cryptographic operations. KeePassXC uses C++ for object-oriented design, whereas OpenSC uses C for system-level programming and broader compatibility with hardware devices.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

OpenSC documentation

Manual pages for the OpenSC command line tools as well as for the OpenSC configuration files are available online and typically distributed along with your installation.

The OpenSC Wiki includes, among others, information for:

Downloads

Latest release

The latest stable version of OpenSC is available on Github. It is available as

  • Windows installer for 64 bit and 32 bit programs (OpenSC*_win64.msi and OpenSC*_win32.msi)
  • macOS installer (OpenSC*.dmg)
  • Source code distribution (opensc*.tar.gz)

Nightly build

The latest source code is available through GitHub. Nightly builds are available by their git hash in branches of OpenSC/Nightly.

Build and testing status

Linux build OSX build AppVeyor CI Build Status Coverity Scan Status CodeQL Fuzzing Status CII Best Practices

Build and test status of specific cards:

CardsStatus
CACCAC
virt_CACardvirt_CACard
CoolkeyCoolkey
PivAppletPIV
OpenPGP AppletOpenPGP
GidsAppletGIDS
IsoAppletIsoApplet
OsEID (MyEID)OsEID (MyEID)
SmartCardHSMSmartCardHSM
ePass2003ePass2003