QtKeychain Documentation

repository·main·Indexed 19 days ago

https://github.com/frankosterfeld/qtkeychain

A Qt-based API providing a cross-platform interface for securely storing passwords and sensitive data using native system credential stores, including macOS Keychain, GNOME Keyring, KWallet, Windows Credential Store, Android Keystore, and iOS Keychain. Supports Qt 5 and Qt 6, requiring C++11 or newer.

Tokens
531
Snippets
1
Records
3
Agent score
17%

What's inside QtKeychain

  1. How QtKeychain stores secret data across platforms

    main

    QtKeychain provides a unified Qt API for securely storing passwords and secret data. The underlying storage mechanism is automatically selected based on the operating system:

    • macOS: Uses the macOS Keychain.
    • Linux/Unix: Attempts to use GNOME Keyring. If unavailable, it tries KWallet (via D-Bus). It also supports libsecret.
    • Windows: Uses the Windows Credential Store by default (Windows 7+).
      • Note: You can disable the Credential Store by passing -DUSE_CREDENTIAL_STORE=OFF to CMake. In this mode, it uses the CryptProtectData Windows API to encrypt data and persists it via QSettings.
    • WebAssembly: Uses a transient HTML bridge to trigger the browser's native password manager (auto-fill/save prompts) and the navigator.credentials Credential Management API.
    • Android: Uses the Android Keystore system.
    • iOS: Uses the iOS Keychain.

    Security Note: In unsupported environments, QtKeychain will report an error rather than storing data unencrypted. To explicitly allow unencrypted storage in unsupported environments, use setInsecureFallback(true).

  2. Requirements for using QtKeychain

    main

    To use QtKeychain, ensure your environment meets the following requirements:

    • Qt Version: QtKeychain 0.12 and newer supports both Qt 5 and Qt 6. (Older versions support Qt 4 and Qt 5).
    • C++ Standard: Requires a compiler with C++11 support or newer.
  3. Integrate QtKeychain with QML via Context Properties

    main

    To use QtKeychain functionality within a QML application, wrap your keychain logic in a class (e.g., KeyChainClass) that inherits from QObject. You can then expose this class to the QML engine using engine.rootContext()->setContextProperty(). This allows QML components to call C++ methods defined in your keychain wrapper directly.

    KeyChainClass keyChainClass;
    
    // Expose the keychain instance to QML under the name "KeyChain"
    engine.rootContext()->setContextProperty("KeyChain", &keyChainClass);
    
    engine.load(url);