Package de.svenkubiak.webpush4j
Class WebPush
java.lang.Object
de.svenkubiak.webpush4j.WebPush
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic WebPushcrerate()static Encryptedencrypt(byte[] payload, org.bouncycastle.jce.interfaces.ECPublicKey userPublicKey, byte[] userAuth, Encoding encoding) Encrypt the payload.protected final HttpRequestprepareRequest(Notification notification, Encoding encoding) voidsend(Notification notification) <T> TsetGcmApiKey(String gcmApiKey) Set the Google Cloud Messaging (GCM) API key<T> TsetKeyPair(KeyPair keyPair) Set the public and private key (for VAPID).<T> TsetPrivateKey(String privateKey) Set the public key using a base64url-encoded string.<T> TsetPrivateKey(PrivateKey privateKey) Set the private key (for VAPID)<T> TsetPublicKey(String publicKey) Set the public key using a base64url-encoded string.<T> TsetPublicKey(PublicKey publicKey) Set the public key (for VAPID)<T> TsetSubject(String subject) Set the JWT subject (for VAPID)protected booleanCheck if VAPID is enabledwithGcmApiKey(String gcmApiKey) withKeyPair(KeyPair keyPair) withPrivateKey(String privateKey) withPublicKey(String publicKey) withSubject(String subject)
-
Constructor Details
-
WebPush
public WebPush()
-
-
Method Details
-
crerate
-
withGcmApiKey
-
withKeyPair
-
withPublicKey
public WebPush withPublicKey(String publicKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException -
withPrivateKey
public WebPush withPrivateKey(String privateKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException -
withSubject
- Throws:
GeneralSecurityException
-
send
public void send(Notification notification) throws GeneralSecurityException, IOException, org.jose4j.lang.JoseException - Throws:
GeneralSecurityExceptionIOExceptionorg.jose4j.lang.JoseException
-
encrypt
public static Encrypted encrypt(byte[] payload, org.bouncycastle.jce.interfaces.ECPublicKey userPublicKey, byte[] userAuth, Encoding encoding) throws GeneralSecurityException Encrypt the payload. Encryption uses Elliptic curve Diffie-Hellman (ECDH) cryptography over the prime256v1 curve.- Parameters:
payload- Payload to encrypt.userPublicKey- The user agent's public key (keys.p256dh).userAuth- The user agent's authentication secret (keys.auth).encoding-- Returns:
- An Encrypted object containing the public key, salt, and ciphertext.
- Throws:
GeneralSecurityException
-
prepareRequest
protected final HttpRequest prepareRequest(Notification notification, Encoding encoding) throws GeneralSecurityException, IOException, org.jose4j.lang.JoseException - Throws:
GeneralSecurityExceptionIOExceptionorg.jose4j.lang.JoseException
-
setGcmApiKey
Set the Google Cloud Messaging (GCM) API key- Parameters:
gcmApiKey-- Returns:
-
getGcmApiKey
-
getSubject
-
setSubject
Set the JWT subject (for VAPID)- Parameters:
subject-- Returns:
-
setKeyPair
Set the public and private key (for VAPID).- Parameters:
keyPair-- Returns:
-
getPublicKey
-
setPublicKey
public <T> T setPublicKey(String publicKey) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException Set the public key using a base64url-encoded string.- Parameters:
publicKey-- Returns:
- Throws:
NoSuchAlgorithmExceptionNoSuchProviderExceptionInvalidKeySpecException
-
getPrivateKey
-
getKeyPair
-
setPublicKey
Set the public key (for VAPID)- Parameters:
publicKey-- Returns:
-
setPrivateKey
public <T> T setPrivateKey(String privateKey) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException Set the public key using a base64url-encoded string.- Parameters:
privateKey-- Returns:
- Throws:
NoSuchAlgorithmExceptionNoSuchProviderExceptionInvalidKeySpecException
-
setPrivateKey
Set the private key (for VAPID)- Parameters:
privateKey-- Returns:
-
vapidEnabled
protected boolean vapidEnabled()Check if VAPID is enabled- Returns:
-