Skip to content

Instantly share code, notes, and snippets.

@jannikolai
Created July 16, 2014 09:52
Show Gist options
  • Save jannikolai/a61fb8993e85479a099a to your computer and use it in GitHub Desktop.
Save jannikolai/a61fb8993e85479a099a to your computer and use it in GitHub Desktop.
Ruby script to migrate Enpass to KeePass
# Converts the Export of Enpass to a format readable by KeePass
#
# This file is not heavily tested but worked for me in most cases. Of course
# some manual steps to regroup and edit the entries had to be done afterwards
#
# Exported with Enpass 4.0.1: File > Export > TXT
# ruby convert_enpass_to_keepass.rb FILENAME.txt > OUTPUT.xml
# Imported with KeePassX 0.4.3: File > Import from ... > KeePassX XML (*.xml)
require 'set'
require 'time'
text=File.open(ARGV[0]).read
text.gsub!(/\r\n?/, "\n")
e_entries = Set.new
e_entry = []
text.each_line do |line|
if line != "\n"
e_entry.push(line.strip)
else
e_entries.add(e_entry)
e_entry = []
end
end
pre = "<!DOCTYPE KEEPASSX_DATABASE>
<database>
<group>
<title>Import from Enpass</title>
<icon>1</icon>
"
post = " </group>
</database>"
output_xml = pre
e_entries.each do |e|
url = ""
3.upto(e.size-1).each do |i|
url = e[i] if e[i].match(/^http/)
end
output_xml = output_xml +
" <entry>
<title>#{e[0]}</title>
<username>#{e[1]}</username>
<password>#{e[2]}</password>
<url>#{url}</url>
<comment>"
3.upto(e.size-1).each do |i|
output_xml = output_xml + "#{e[i]}<br/>"
end
output_xml = output_xml + "</comment>
<icon>1</icon>
<creation>#{Time.now.iso8601}</creation>
<lastaccess>#{Time.now.iso8601}</lastaccess>
<lastmod>#{Time.now.iso8601}</lastmod>
<expire>Never</expire>
</entry>
"
end
output_xml = output_xml + post
print output_xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment