Interface VAPIDKeyPair


  • public interface VAPIDKeyPair

    This interface represents a signing key pair for the Voluntary Application Server Identification (VAPID) described in RFC8292.

    Usually, an instance of this interface is obtained by using a factory method of VAPIDKeyPairs.

    Example:
     VAPIDKeyPair vapidKeyPair = VAPIDKeyPairs.of(
          PrivateKeySources.ofPEMFile(new File(privateKeyFilePath).toPath()),
          PublicKeySources.ofPEMFile(new File(publicKeyFilePath).toPath())
     );
    
     ........
    
     HttpRequest request = StandardHttpClientRequestPreparer.getBuilder()
         .pushSubscription(subscription)
         .vapidJWTExpiresAfter(15, TimeUnit.MINUTES)
         .vapidJWTSubject("mailto:example@example.com")
         .pushMessage(message)
         .ttl(1, TimeUnit.HOURS)
         .urgencyLow()
         .topic("MyTopic")
         .build(vapidKeyPair)
         .toRequest();
    
     

    As explained in RFC8292, the key pair MUST be usable with the Elliptic Curve Digital Signature Algorithm (ECDSA) over the P-256 curve.

    Thread Safety:

    Depends on implementations. See VAPIDKeyPairs.

    Author:
    Tomoki Sato
    See Also:
    PrivateKeySource, PublicKeySource, VAPIDKeyPairs, VAPIDJWTGenerator, VAPIDJWTParam
    • Method Detail

      • extractPublicKeyInUncompressedForm

        byte[] extractPublicKeyInUncompressedForm()

        Extracts the octet sequence of the public key in uncompressed form (65-byte array starting with 0x04).

        Typically, the extracted octet sequence is sent to browsers and used to set the 'applicationServerKey' field. (See also: W3C document for Push API)

        Returns:
        the octet sequence of the public key in uncompressed form.
        See Also:
        PushSubscription, extractPublicKeyInUncompressedFormAsString()
      • extractPublicKeyInUncompressedFormAsString

        String extractPublicKeyInUncompressedFormAsString()

        Extracts the public key in uncompressed form (65-byte array starting with 0x04) encoded using base64url without padding.

        Typically, the extracted text is sent to browsers and used to set the 'applicationServerKey' field. (See also: W3C document for Push API)

        This 'String' version of the public key is useful if you want to send the public key to browsers as a text format. For example, you can send the public key as a field of JSON('application/json') response by extracting the public key through this method.

        Returns:
        the public key in uncompressed form encoded using base64url without padding.
        See Also:
        PushSubscription, extractPublicKeyInUncompressedForm()
      • generateAuthorizationHeaderValue

        String generateAuthorizationHeaderValue​(VAPIDJWTParam jwtParam)
        Generates a credential(that uses 'vapid' authentication scheme) used to set an Authorization header field when requesting the delivery of a push message.
        Parameters:
        jwtParam - parameters to use when generating JSON Web Token (JWT).
        Returns:
        a credential like 'vapid t=eyJ0e....., k=BA1H....'.