@@ -39,33 +39,6 @@ public static class MySubscription {
39
39
private String publicKey ;
40
40
private String auth ;
41
41
42
- /**
43
- * Returns the base64 encoded public key string as a byte[]
44
- */
45
- public byte [] getKeyAsBytes () {
46
- return Base64 .getDecoder ().decode (publicKey );
47
- }
48
-
49
- /**
50
- * Returns the base64 encoded auth string as a byte[]
51
- */
52
- public byte [] getAuthAsBytes () {
53
- return Base64 .getDecoder ().decode (auth );
54
- }
55
-
56
- /**
57
- * Returns the base64 encoded public key as a PublicKey object
58
- */
59
- public PublicKey getUserPublicKey () throws NoSuchAlgorithmException , InvalidKeySpecException , NoSuchProviderException {
60
-
61
- KeyFactory kf = KeyFactory .getInstance ("ECDH" , BouncyCastleProvider .PROVIDER_NAME );
62
- ECNamedCurveParameterSpec ecSpec = ECNamedCurveTable .getParameterSpec ("secp256r1" );
63
- ECPoint point = ecSpec .getCurve ().decodePoint (getKeyAsBytes ());
64
- ECPublicKeySpec pubSpec = new ECPublicKeySpec (point , ecSpec );
65
-
66
- return kf .generatePublic (pubSpec );
67
- }
68
-
69
42
public String getNotificationEndPoint () {
70
43
return notificationEndPoint ;
71
44
}
@@ -104,8 +77,8 @@ public static void main(String[] args) throws NoSuchProviderException, NoSuchAlg
104
77
Security .addProvider (new BouncyCastleProvider ());
105
78
}
106
79
107
- pushService .setPublicKey (Utils . loadPublicKey ( "BBYCxwATP2vVgw7mMPHJfT6bZrJP2iUV7OP_oxHzEcNFenrX66D8G34CdEmVULNg4WJXfjkeyT0AT9LwavpN8M4=" ) );
108
- pushService .setPrivateKey (Utils . loadPrivateKey ( "AKYLHgp-aV3kOys9Oy6QgxNI6OGIlOB3G6kjGvhl57j_" ) );
80
+ pushService .setPublicKey ("BBYCxwATP2vVgw7mMPHJfT6bZrJP2iUV7OP_oxHzEcNFenrX66D8G34CdEmVULNg4WJXfjkeyT0AT9LwavpN8M4=" );
81
+ pushService .setPrivateKey ("AKYLHgp-aV3kOys9Oy6QgxNI6OGIlOB3G6kjGvhl57j_" );
109
82
110
83
SpringApplication .run (WebPushDemoApplication .class , args );
111
84
}
@@ -123,14 +96,14 @@ public void unsubscribe(MySubscription subscription) {
123
96
}
124
97
125
98
@ PostMapping ("/notify-all" )
126
- public byte [] notifyAll (@ RequestBody byte [] message ) throws GeneralSecurityException , IOException , JoseException , ExecutionException , InterruptedException {
99
+ public String notifyAll (@ RequestBody String message ) throws GeneralSecurityException , IOException , JoseException , ExecutionException , InterruptedException {
127
100
128
101
for (MySubscription subscription : subscriptions .values ()) {
129
102
130
103
Notification notification = new Notification (
131
104
subscription .getNotificationEndPoint (),
132
- subscription .getUserPublicKey (),
133
- subscription .getAuthAsBytes (),
105
+ subscription .getPublicKey (),
106
+ subscription .getAuth (),
134
107
message );
135
108
136
109
pushService .send (notification );
0 commit comments