Created
January 30, 2024 00:38
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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