- 
      
 - 
        
Save hangj/9870aac84349a54acfe31d2527c9b5e0 to your computer and use it in GitHub Desktop.  
    Python based VAPID key-pair generator
  
        
  
    
      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
    
  
  
    
  | import base64 | |
| import ecdsa | |
| def generate_vapid_keypair(): | |
| """ | |
| Generate a new set of encoded key-pair for VAPID | |
| """ | |
| pk = ecdsa.SigningKey.generate(curve=ecdsa.NIST256p) | |
| vk = pk.get_verifying_key() | |
| return { | |
| 'private_key': base64.urlsafe_b64encode(pk.to_string()).strip(b"="), | |
| 'public_key': base64.urlsafe_b64encode(b"\x04" + vk.to_string()).strip(b"=") | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment