Super simple and small Web Push and Notification service
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

27 lines
787 B

  1. # (A) REQUIRED MODULES
  2. import base64
  3. import ecdsa
  4. # (B) GENERATE KEYS
  5. # CREDITS : https://gist.github.com/cjies/cc014d55976db80f610cd94ccb2ab21e
  6. pri = ecdsa.SigningKey.generate(curve=ecdsa.NIST256p)
  7. pub = pri.get_verifying_key()
  8. private = base64.urlsafe_b64encode(pri.to_string()).decode("utf-8").strip("=")
  9. public = base64.urlsafe_b64encode(b"\x04" + pub.to_string()).decode("utf-8").strip("=")
  10. import pathlib
  11. keydir = pathlib.Path('keys')
  12. keydir.mkdir(exist_ok=True)
  13. with open(keydir / 'public_key.txt', 'w') as fp:
  14. print(public, file=fp)
  15. with open(keydir / 'private_key.txt', 'w') as fp:
  16. print(private, file=fp)
  17. with open(keydir / 'private_key.pem', 'wb') as fp:
  18. #print(pri.to_pem(), file=fp)
  19. # ecdsa is broken, to_pem returns bytes instead of a str
  20. fp.write(pri.to_pem())