Reputation: 597
Hi I generate the VAPID key using the following function, as I had searched, vapid key shall be created only once for a project and we can use that a vapid key while sending push notifications, I had generated the vapid key, but I have to store the vapid key in some place and retrieve them whenever sending a push notification. Please advice how can I store the vapid key
fun generateVapidPublicKey(uniqueVisitorId: String): String {
val keyPair= this.webPushService.generateVapidKeyPair()
val publicKey = keyPair!!.public as ECPublicKey
val encodedPublicKey = Utils.encode(publicKey)
return Base64Encoder.encodeUrl(encodedPublicKey)
}
Convert to KeyPair from string
fun generateKeyPair(): KeyPair {
return KeyPair(
Utils.loadPublicKey("ODyt-8tafKI35yE-tz9eLah0goe63CeFYGmnmIaLe8="),
Utils.loadPrivateKey(
"BPO9QDvvjnLCAusoZ1vXZQjVaCG3sOP9vd-VHSUOoN3Jj3VXXSQPzQ31NMrK76N-eODmioJXUpN0gfoIBORZrt="
)
)
}
Throws "Invalid point encoding 0x38"
Upvotes: 1
Views: 1959
Reputation: 35460
Yes, you should use only one vapid key per project. You can store the vapid key in your database or in a configuration file.
Upvotes: 1