Skip to content

Instantly share code, notes, and snippets.

@tonytonyjan
Created April 11, 2020 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonytonyjan/40c236698e474db502ac857380e7534c to your computer and use it in GitHub Desktop.
Save tonytonyjan/40c236698e474db502ac857380e7534c to your computer and use it in GitHub Desktop.
Generate VAPID key pair by pure Ruby based on RFC8292
# https://tools.ietf.org/html/rfc8292
require 'openssl'
require 'base64'
ec = OpenSSL::PKey::EC.generate('prime256v1')
puts(
Base64.urlsafe_encode64(ec.public_key.to_bn.to_s(2), padding: false),
Base64.urlsafe_encode64(ec.private_key.to_s(2), padding: false)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment