111
public static string ReadPasswordKDEWallet (string folder, string username)
113
if (String.IsNullOrEmpty (folder) || String.IsNullOrEmpty (username))
114
throw new ArgumentException ("folder, username", "cannot be empty");
116
// Get name of the local wallet
117
SafeProcess pc = new SafeProcess ();
118
pc.Arguments = new string[] { "dcop", "kded", "kwalletd", "localWallet" };
119
pc.RedirectStandardOutput = true;
120
pc.RedirectStandardError = false;
124
string localWallet = null;
125
using (StreamReader pout = new StreamReader (pc.StandardOutput))
126
localWallet = pout.ReadLine ();
129
if (String.IsNullOrEmpty (localWallet) || localWallet == "-1")
130
throw new ArgumentException ("kwalletd", "Unable to reach local KDE wallet");
133
pc = new SafeProcess ();
134
pc.Arguments = new string[] {"dcop", "kded", "kwalletd", "open", localWallet, "K" };
135
pc.RedirectStandardOutput = true;
136
pc.RedirectStandardError = false;
140
string wallet_id = null;
141
using (StreamReader pout = new StreamReader (pc.StandardOutput))
142
wallet_id = pout.ReadLine ();
145
if (String.IsNullOrEmpty (wallet_id) || wallet_id == "-1")
146
throw new ArgumentException ("kwalletd", "Unable to open local KDE wallet");
148
// Read password from the given folder and for the given username
149
pc = new SafeProcess ();
150
pc.Arguments = new string[] {"dcop", "kded", "kwalletd", "readPassword", wallet_id, folder, username };
151
pc.RedirectStandardOutput = true;
152
pc.RedirectStandardError = false;
156
string password = null;
157
using (StreamReader pout = new StreamReader (pc.StandardOutput))
158
password = pout.ReadLine ();
161
if (String.IsNullOrEmpty (password))
162
throw new ArgumentException ("kwalletd", "Unable to read password.");
167
public static void StorePasswordKDEWallet (string folder, string username, string password)
169
if (String.IsNullOrEmpty (folder) || String.IsNullOrEmpty (username) || String.IsNullOrEmpty (password))
170
throw new ArgumentException ("folder, username or password", "cannot be empty");
172
// Get name of the local wallet
173
SafeProcess pc = new SafeProcess ();
174
pc.Arguments = new string[] { "dcop", "kded", "kwalletd", "localWallet" };
175
pc.RedirectStandardOutput = true;
176
pc.RedirectStandardError = false;
180
string localWallet = null;
181
using (StreamReader pout = new StreamReader (pc.StandardOutput))
182
localWallet = pout.ReadLine ();
185
if (String.IsNullOrEmpty (localWallet) || localWallet == "-1")
186
throw new ArgumentException ("kwalletd", "Local KDE Wallet is not found. Please run kwalletmanager to enable KDE Wallet.");
189
pc = new SafeProcess ();
190
pc.Arguments = new string[] {"dcop", "kded", "kwalletd", "open", localWallet, "K" };
191
pc.RedirectStandardOutput = true;
192
pc.RedirectStandardError = false;
196
string wallet_id = null;
197
using (StreamReader pout = new StreamReader (pc.StandardOutput))
198
wallet_id = pout.ReadLine ();
201
if (String.IsNullOrEmpty (wallet_id) || wallet_id == "-1")
202
throw new ArgumentException ("kwalletd", "Unable to open local KDE wallet");
204
// Write given password for the given folder and username
205
pc = new SafeProcess ();
206
pc.Arguments = new string[] {"dcop", "kded", "kwalletd", "writePassword", wallet_id, folder, username, password };
207
pc.RedirectStandardOutput = true;
208
pc.RedirectStandardError = false;
213
using (StreamReader pout = new StreamReader (pc.StandardOutput))
214
password = pout.ReadLine ();
218
throw new ArgumentException ("kwalletd", "Unable to save password.");