{"id":19260617,"url":"https://github.com/evant/webpush-encryption","last_synced_at":"2026-01-27T10:11:30.326Z","repository":{"id":159433726,"uuid":"634638350","full_name":"evant/webpush-encryption","owner":"evant","description":"A lightweight webpush encryption/decryption library","archived":false,"fork":false,"pushed_at":"2024-04-28T03:59:20.000Z","size":106,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-18T21:35:34.092Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evant.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-30T19:14:36.000Z","updated_at":"2024-04-28T03:59:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"97102e8b-db71-462a-b255-672866c03fe9","html_url":"https://github.com/evant/webpush-encryption","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/evant/webpush-encryption","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Fwebpush-encryption","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Fwebpush-encryption/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Fwebpush-encryption/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Fwebpush-encryption/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evant","download_url":"https://codeload.github.com/evant/webpush-encryption/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evant%2Fwebpush-encryption/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28811553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T07:41:26.337Z","status":"ssl_error","status_checked_at":"2026-01-27T07:41:08.776Z","response_time":168,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T19:22:04.967Z","updated_at":"2026-01-27T10:11:30.310Z","avatar_url":"https://github.com/evant.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# webpush-encryption\n\nA lightweight webpush encryption/decryption library for kotlin/android\n\nThis library supports both the 'aes128gcm' content encoding as specified in the\n[WebPush encryption RFC](https://datatracker.ietf.org/doc/html/rfc8291) as well as the legacy 'aesgcm' encoding as\ndefined in the [draft RFC](https://datatracker.ietf.org/doc/html/draft-ietf-webpush-encryption-04).\n\nIt is built with [okio](https://square.github.io/okio/) and exposes types as `ByteString` and `Source`. These can easily\nbe converted to and from other forms using the built-in functions on those types.\n\n## Download\n\n```kotlin\nimplemenation(\"me.tatarka.webpush:webpush-encryption:0.2.0\")\n```\n\n## Usage\n\n### Encryption\n\nTo encrypt, construct a WebPush object by calling `WebPush.encrypt()`.\n\n```kotlin\nval webPush = WebPush.encrypt(\n    authSecret = authSecret,\n    keys = keys,\n    body = body,\n    encoding = ContentEncoding.aes128gcm // or ContentEncoding.aesgcm\n)\n```\n\nwhere:\n\n- `authSecret` is the 16-byte shared auth secret.\n- `keys` is the server public/private key pair, which must be a p-256 elliptic curve (See later section on how to\n  generate).\n- `body` is the plaintext payload to encrypt.\n\nYou can then pass along the returned WebPush with the server of your choice. It includes `headers` and\nthe `encryptedBody`.\n\n### Decryption\n\nTo decrypt, construct a WebPush object using its constructor then call `webPush.decrypt()`.\n\n```kotlin\nval webPush = WebPush(headers = headers, encryptedBody = encrypedBody)\nval bodyPlainText = webPush.decrypt(\n    authSecret = authSecret,\n    keys = keys\n)\n```\n\nwhere:\n\n- `authSecret` is the 16-byte shared auth secret.\n- `keys` is the client public/private key pair, which must be a p-256 elliptic curve (See later section on how to\n  generate).\n\n### Generating And Sharing Keys\n\n#### Auth Secret\n\nThe auth secret is a random set of 16 bytes. You may use the convenience method `WebPush.generateAuthSecret()` or\ngenerate them yourself. Note: It's recommended to use a secure random number generator.\n\n#### Public/Private Key Pair\n\nBoth the server and the client need to generate a P-256 elliptic curve key pair. You can do this on the jvm with:\n\n```kotlin\nval keyPair = KeyPairGenerator.getInstance(\"EC\").apply {\n    initialize(ECGenParameterSpec(\"secp256r1\"))\n}.generateKeyPair()\n```\n\nor on Android storing in the AndroidKeyStore (min api 31) with:\n\n```kotlin\nval keyPair = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_EC, \"AndroidKeyStore\")\n    .apply {\n        initialize(\n            KeyGenParameterSpec.Builder(KeyAlias, KeyProperties.PURPOSE_AGREE_KEY)\n                .setAlgorithmParameterSpec(ECGenParameterSpec(\"secp256r1\"))\n                .build()\n        )\n    }.generateKeyPair()\n```\n\n#### Sharing\n\nYou will likely want share the auth secret and public key from the client to the server. To accomplish this you may want\nto base64-url-encode them. You can do this with:\n\n```kotlin\nval authSecretBase64 = authSecret.base64Url()\nval publicKeyBase64 = WebPush.encodePublicKey(publicKey).base64Url()\n```\n\n### Limitations\n\nOnly 1 record of the default size of 4096 bytes is currently supported. A plaintext payload of more than 3993 bytes\nusing 'aes128gcm' (or 4077 bytes using 'aesgcm') will be rejected.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevant%2Fwebpush-encryption","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevant%2Fwebpush-encryption","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevant%2Fwebpush-encryption/lists"}