Skip to content

Commit

Permalink
separate key writing to function
Browse files Browse the repository at this point in the history
  • Loading branch information
hannob committed Jul 24, 2024
1 parent def7b0f commit 3d9257f
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions keyfinder
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,23 @@ def findkeys(data):
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption(),
)
akeys.append(xkey)
akeys.append(xkey.decode())
return akeys


def writekey(key, fn, path):
if os.path.exists(f"{path}/{fn}.key"):
c = 0
while True:
if not os.path.exists(f"{path}/{fn}.{c}.key"):
fn = f"{ofn}.{c}"
break
c += 1
fn += ".key"
with open(f"{path}/{fn}", "w") as f:
f.write(key)


if __name__ == "__main__":

ap = argparse.ArgumentParser()
Expand All @@ -66,13 +79,4 @@ if __name__ == "__main__":
ofn = fn
if ofn.endswith(".key"):
ofn = ofn[0:-4]
if os.path.exists(f"{args.outdir}/{ofn}.key"):
c = 0
while True:
if not os.path.exists(f"{args.outdir}/{ofn}.{c}.key"):
ofn = f"{ofn}.{c}"
break
c += 1
ofn += ".key"
with open(f"{args.outdir}/{ofn}", "w") as f:
f.write(k.decode())
writekey(k, ofn, args.outdir)

0 comments on commit 3d9257f

Please sign in to comment.