Vapid::KeyPair
Represents an ES256 (ECDSA using P-256 curve and SHA-256) key pair used for VAPID authentication.
Usage
# Generate a new key pair
key_pair = Vapid::KeyPair.generate
# Access keys in various formats
puts key_pair.public_key_bytes # Raw bytes
puts key_pair.public_key_base64 # URL-safe Base64
puts key_pair.private_key_pem # PEM format
# Load from existing private key
key_pair = Vapid::KeyPair.from_pem(pem_string)
Constructors
Loads a KeyPair from a PEM-encoded private key string
pem = File.read("private_key.pem")
key_pair = Vapid::KeyPair.from_pem(pem)
generate
Generates a new ES256 key pair using the P-256 curve
key_pair = Vapid::KeyPair.generate
Instance methods
ec_key
Sourceprivate_key_pem
Returns the private key in PEM format
pem = key_pair.private_key_pem
File.write("private_key.pem", pem)
public_key_base64
Returns the public key in URL-safe Base64 format (without padding) This format is used in the 'p256ecdsa' header for VAPID
public_key = key_pair.public_key_base64
# => "BKj3v..."
public_key_bytes
Returns the raw public key bytes in uncompressed format (65 bytes) Format: 0x04 || X || Y where X and Y are 32-byte coordinates