zaru / webpush

webpush, Encryption Utilities for Web Push protocol
MIT License
396 stars 73 forks source link

Add PEM support to import / export keys #65

Closed collimarco closed 5 years ago

collimarco commented 5 years ago

I have added two helper methods for importing / exporting keys in PEM format. It is useful for interoperability between different libraries and services that store or use the keys in different formats. For example it is useful in order to use this library if you already have existing keys in PEM format. It is also useful if you want to store your keys in PEM format, which is a de facto standard for keys.

# example import (from PEM to base64)
vapid_key = Webpush::VapidKey.from_pem "YOUR PEM GOES HERE"
vapid_key.public_key
vapid_key.private_key

# example export (to PEM)
vapid_key = Webpush.generate_key
vapid_key.to_pem
zaru commented 5 years ago

@collimarco Thanks for awesome PR! Please write example to README.

collimarco commented 5 years ago

Thanks @zaru for the positive feedback! I have added an improvement to support PEM directly and added the examples to the readme.

zaru commented 5 years ago

released!