Skip to content

Instantly share code, notes, and snippets.

@Tzrlk
Created January 30, 2024 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tzrlk/b71a4d87b7de393451e2b03a01ea6a7a to your computer and use it in GitHub Desktop.
Save Tzrlk/b71a4d87b7de393451e2b03a01ea6a7a to your computer and use it in GitHub Desktop.
A KeePass script to display entries in a database with different character encodings.
public static void Main() {
CommandLineArgs args = new CommandLineArgs(Environment.GetCommandLineArgs());
String infile = args["infile"];
if (String.IsNullOrEmpty(infile)) {
Console.WriteLine("No input file specified.");
throw new Exception("No input file specified.");
}
String pass = args["pass"];
if (String.IsNullOrEmpty(pass)) {
Console.WriteLine("No password provided.");
throw new Exception("No password provided.");
}
CompositeKey auth = new CompositeKey();
auth.AddUserKey(new KcpPassword(pass));
IOConnectionInfo conn = new IOConnectionInfo();
conn.Path = infile;
PwDatabase db = new PwDatabase();
try {
Console.WriteLine("Attempting to open database {0}", infile);
db.Open(conn, auth, null);
} catch (Exception error) {
Console.WriteLine("Unable to open database: {0}", error);
throw new Exception("Unable to open database.", error);
}
Console.WriteLine("Fetching root database entries.");
PwObjectList<PwEntry> entries = db.RootGroup.GetEntries(true);
foreach (PwEntry entry in entries) {
Console.WriteLine(entry.Strings.Get("Title"));
byte[] password = entry.Strings.Get("Password").ReadUtf8();
foreach (StrEncodingInfo encoding in StrUtil.Encodings) {
Console.WriteLine("{0} = {1}",
encoding.Name.PadRight(7, ' '),
encoding.Encoding.GetString(password));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment