Skip to content

Cross-platform secure credential storage - port of keytar to pure C++ library

License

Notifications You must be signed in to change notification settings

Shadowrom2020/libcred

 
 

Repository files navigation

libcred - cross-platform credentials helper library

This C++ library is a fork of node-keytar and tests are forked from keytar to provide standalone C++ access to cross-platform credentials management.

The library can be used to get, add, replace, and delete passwords in system's keychain. On macOS the passwords are managed by the Keychain, on Linux they are managed by the Secret Service API/libsecret, and on Windows they are managed by Credential Vault.

Usage example

#include <string>
#include <iostream>

// libcred includes
#include <libcred.hpp>

int main() {
    // Test values
    const std::string service("libcred-test-service");
    const std::string account("[email protected]");
    const std::string password("$uP3RseCr1t!");
    const std::string new_password("Ub3R$3CrE7!?!");
    std::string err;
    // Add a password
    if (libcred::set_password(service, account, password, &err) != libcred::SUCCESS) {
        std::cerr << "error: unable to add password " << err << std::endl;
        return 1;
    }
    std::cout << "Set password successfully." << std::endl;

    // Get a password
    std::string retrieved;
    if (libcred::get_password(service, account, &retrieved, &err) != libcred::SUCCESS) {
        std::cerr << "error: unable to get password " << err  << std::endl;
        return 1;
    }
    std::cout << "Got password successfully." << std::endl;

    // Find a password
    std::string found;
    if (libcred::find_password(service, &found, &err) != libcred::SUCCESS) {
        std::cerr << "error: unable to find password " << err << std::endl;
        return 1;
    }
    std::cout << "Found password successfully." << std::endl;

    // Delete a password
    if (libcred::delete_password(service, account, &err) != libcred::SUCCESS) {
        std::cerr << "error: unable to delete password " << err << std::endl;
        return 1;
    }
    std::cout << "Deleted password successfully." << std::endl;

    // All done
    return 0;
}

About

Cross-platform secure credential storage - port of keytar to pure C++ library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 94.7%
  • Meson 5.3%