Skip to content

purejava/kdewallet

Repository files navigation

kdewallet

KWallet

Publish to Maven Central Codacy Badge Maven Central License

A Java library for storing secrets on linux in a KDE wallet over D-Bus.

The KDE wallet functionality itself is provided by the kwallet daemon kwalletd.

Usage

The library provides an API, which sends secrets over D-Bus and has D-Bus signaling enabled.

Dependency

Add kdewallet as a dependency to your project.

Gradle

implementation group: 'org.purejava', name: 'kdewallet', version: '1.6.0'

Maven

<dependency>
    <groupId>org.purejava</groupId>
    <artifactId>kdewallet</artifactId>
    <version>1.6.0</version>
</dependency>

Accessing the kwallet daemon

Creating a folder in a wallet can be done like this:

package org.example;

import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder;
import org.freedesktop.dbus.exceptions.DBusException;
import org.kde.KWallet;

import java.io.IOException;

public class App {
    public static void main(String[] args) {
        DBusConnection connection = null;

        try {
            connection = DBusConnectionBuilder.forSessionBus().withShared(false).build();

            var service = connection.getRemoteObject("org.kde.kwalletd6",
                    "/modules/kwalletd6", KWallet.class);

            var wallet = "kdewallet";
            var wId = 0;
            var appid = "Tester";
            var handle = service.open(wallet, wId, appid);
            var folder = "Test-Folder";
            var created = service.createFolder(handle, folder, appid);
            service.close(handle, false, appid);
        } catch (DBusException e) {
            System.out.println(e.toString() + e.getCause());
        }
        try {
            connection.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Signal handling

D-Bus signals are emitted on every change to a wallet, e.g. when it's opened asynchronously, closed etc. Listening to these signals can be done asynchronously with few effort.

For the complete API and examples see the Wiki.

Thank you

Thanks to David M., who wrote an improved version of Java DBus library provided by freedesktop.org. Thanks to Sebastian Wiesendahl, who implemented the original core messaging interface to DBus in his secret-service library.

Copyright

Copyright (C) 2020-2025 Ralph Plawetzki

About

A Java library for storing secrets on linux in a KDE wallet over D-Bus

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •  

Languages