Created
November 6, 2016 03:02
-
-
Save princebot/a8fbe289843a268d13ff2f20fc3606e7 to your computer and use it in GitHub Desktop.
Convert private keys saved in LastPass as SSH Key Secure Notes back to a usable format
This file contains hidden or 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
#!/usr/bin/env python | |
"""Convert private keys saved in LastPass back to a usable format. | |
1. Copy-paste key from Secure Note to a local file. | |
2. Run this script passing the file as an argument. | |
3. Formatted key prints to stdout. | |
Example: | |
python rebuild_key.py ~/.ssh/keys/why_lastpass_why > ~/.ssh/keys/fixed | |
""" | |
import re | |
import sys | |
keyfile = sys.argv[1] | |
regex = re.compile(r'(-{5}|,ENCRYPTED|DEK-Info: \S+|\S{64})( +)') | |
with open(keyfile) as f: | |
text = regex.sub(r'\1\n', f.read()) | |
lines = [] | |
for line in text.split('\n'): | |
if not line.strip(): | |
continue | |
if line.startswith('DEK-Info'): | |
line = line + '\n' | |
lines.append(line) | |
key = '\n'.join(lines) | |
print(key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works great! Thanks