{"id":19064995,"url":"https://github.com/open-keychain/openpgp-api","last_synced_at":"2025-10-05T02:06:05.007Z","repository":{"id":16779330,"uuid":"19537602","full_name":"open-keychain/openpgp-api","owner":"open-keychain","description":"OpenPGP API library","archived":false,"fork":false,"pushed_at":"2024-08-15T05:43:13.000Z","size":581,"stargazers_count":140,"open_issues_count":6,"forks_count":53,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-04-03T12:21:42.829Z","etag":null,"topics":["android","api","openkeychain","openpgp"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":false,"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/open-keychain.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":"2014-05-07T14:28:12.000Z","updated_at":"2025-03-28T13:58:10.000Z","dependencies_parsed_at":"2024-11-16T07:03:49.842Z","dependency_job_id":"a8fbd712-a256-43d3-b930-efeab02d30ea","html_url":"https://github.com/open-keychain/openpgp-api","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/open-keychain/openpgp-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-keychain%2Fopenpgp-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-keychain%2Fopenpgp-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-keychain%2Fopenpgp-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-keychain%2Fopenpgp-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/open-keychain","download_url":"https://codeload.github.com/open-keychain/openpgp-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-keychain%2Fopenpgp-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278399690,"owners_count":25980332,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["android","api","openkeychain","openpgp"],"created_at":"2024-11-09T00:48:08.668Z","updated_at":"2025-10-05T02:06:04.989Z","avatar_url":"https://github.com/open-keychain.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OpenPGP API library\n\nThe OpenPGP API provides methods to execute OpenPGP operations, such as sign, encrypt, decrypt, verify, and more without user interaction from background threads. This is done by connecting your client application to a remote service provided by [OpenKeychain](http://www.openkeychain.org) or other OpenPGP providers.\n\n### News\n\n## Version 12\n  * OpenPgpDecryptionResult and OpenPgpSignatureResult are now immutable\n  * Added PROGRESS_MESSENGER and DATA_LENGTH extras for ACTION_DECRYPT_VERIFY. This allows to the client app to get periodic updates for displaying a progress bar on decryption.\n  * Added ACTION_BACKUP\n  * Added special API calls for better K-9 Mail integration:  \n    Check for sender address matching with EXTRA_SENDER_ADDRESS and result in OpenPgpSignatureResult  \n    Opportunistic encryption mode with EXTRA_OPPORTUNISTIC_ENCRYPTION  \n    There is an external ContentProvider at org.sufficientlysecure.keychain.provider.exported for querying available keys (CAUTION: This API is not final!)\n\n[Full changelog here…](https://github.com/open-keychain/openpgp-api/blob/master/CHANGELOG.md)\n\n### License\nWhile OpenKeychain itself is GPLv3+, the API library is licensed under Apache License v2.\nThus, you are allowed to also use it in closed source applications as long as you respect the [Apache License v2](https://github.com/open-keychain/openpgp-api/blob/master/LICENSE).\n\n### Add the API library to your project\n\nAdd this to your build.gradle:\n\n```gradle\nrepositories {\n    maven { url 'https://jitpack.io' }\n}\n\ndependencies {\n    implementation 'com.github.open-keychain.open-keychain:openpgp-api:v5.7.1'\n}\n```\n\n\n### Full example\nA full working example is available in the [example project](https://github.com/open-keychain/openpgp-api/blob/master/example). The [``OpenPgpApiActivity.java``](https://github.com/open-keychain/openpgp-api/blob/master/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java) contains most relevant sourcecode.\n\n### API\n\n[OpenPgpApi](https://github.com/open-keychain/openpgp-api/blob/master/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java) contains all possible Intents and available extras.\n\n### Short tutorial\n\n**This tutorial only covers the basics, please consult the full example for a complete overview over all methods**\n\nThe API is **not** designed around ``Intents`` which are started via ``startActivityForResult``. These Intent actions typically start an activity for user interaction, so they are not suitable for background tasks. Most API design decisions are explained at [the bottom of this wiki page](https://github.com/open-keychain/open-keychain/wiki/OpenPGP-API#internal-design-decisions).\n\nWe will go through the basic steps to understand how this API works, following this (greatly simplified) sequence diagram:\n![](https://github.com/open-keychain/openpgp-api/raw/master/flow.png)\n\nIn this diagram the client app is depicted on the left side, the OpenPGP provider (in this case OpenKeychain) is depicted on the right.\nThe remote service is defined via the [AIDL](http://developer.android.com/guide/components/aidl.html) file [``IOpenPgpService``](https://github.com/open-keychain/openpgp-api/blob/master/openpgp-api/src/main/aidl/org/openintents/openpgp/IOpenPgpService.aidl).\nIt contains only one exposed method which can be invoked remotely:\n```java\ninterface IOpenPgpService {\n    Intent execute(in Intent data, in ParcelFileDescriptor input, in ParcelFileDescriptor output);\n}\n```\nThe interaction between the apps is done by binding from your client app to the remote service of OpenKeychain.\n``OpenPgpServiceConnection`` is a helper class from the library to ease this step:\n```java\nOpenPgpServiceConnection mServiceConnection;\n\npublic void onCreate(Bundle savedInstance) {\n    [...]\n    mServiceConnection = new OpenPgpServiceConnection(this, \"org.sufficientlysecure.keychain\");\n    mServiceConnection.bindToService();\n}\n\npublic void onDestroy() {\n    [...]\n    if (mServiceConnection != null) {\n        mServiceConnection.unbindFromService();\n    }\n}\n```\n\nFollowing the sequence diagram, these steps are executed:\n\n1.  Define an ``Intent`` containing the actual PGP instructions which should be done, e.g.\n    ```java\n    Intent data = new Intent();\n    data.setAction(OpenPgpApi.ACTION_ENCRYPT);\n    data.putExtra(OpenPgpApi.EXTRA_USER_IDS, new String[]{\"dominik@dominikschuermann.de\"});\n    data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);\n    ```\n    Define an ``InputStream`` currently holding the plaintext, and an ``OutputStream`` where you want the ciphertext to be written by OpenKeychain's remote service:\n    ```java\n    InputStream is = new ByteArrayInputStream(\"Hello world!\".getBytes(\"UTF-8\"));\n    ByteArrayOutputStream os = new ByteArrayOutputStream();\n    ```\n    Using a helper class from the library, ``is`` and ``os`` are passed via ``ParcelFileDescriptors`` as ``input`` and ``output`` together with ``Intent data``, as depicted in the sequence diagram, from the client to the remote service.\n    Programmatically, this can be done with:\n    ```java\n    OpenPgpApi api = new OpenPgpApi(this, mServiceConnection.getService());\n    Intent result = api.executeApi(data, is, os);\n    ```\n\n2.  The PGP operation is executed by OpenKeychain and the produced ciphertext is written into ``os`` which can then be accessed by the client app.\n\n3.  A result Intent is returned containing one of these result codes:\n    * ``OpenPgpApi.RESULT_CODE_ERROR``\n    * ``OpenPgpApi.RESULT_CODE_SUCCESS``\n    * ``OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED``\n\n    If ``RESULT_CODE_USER_INTERACTION_REQUIRED`` is returned, an additional ``PendingIntent`` is returned to the client, which must be used to get user input required to process the request.\n    A ``PendingIntent`` is executed with ``startIntentSenderForResult``, which starts an activity, originally belonging to OpenKeychain, on the [task stack](http://developer.android.com/guide/components/tasks-and-back-stack.html) of the client.\n    Only if ``RESULT_CODE_SUCCESS`` is returned, ``os`` actually contains data.\n    A nearly complete example looks like this:\n    ```java\n    switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {\n        case OpenPgpApi.RESULT_CODE_SUCCESS: {\n            try {\n                Log.d(OpenPgpApi.TAG, \"output: \" + os.toString(\"UTF-8\"));\n            } catch (UnsupportedEncodingException e) {\n                Log.e(Constants.TAG, \"UnsupportedEncodingException\", e);\n            }\n\n            if (result.hasExtra(OpenPgpApi.RESULT_SIGNATURE)) {\n                OpenPgpSignatureResult sigResult\n                        = result.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE);\n                [...]\n            }\n            break;\n        }\n        case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: {\n            PendingIntent pi = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);\n            try {\n                startIntentSenderForResult(pi.getIntentSender(), 42, null, 0, 0, 0);\n            } catch (IntentSender.SendIntentException e) {\n                Log.e(Constants.TAG, \"SendIntentException\", e);\n            }\n            break;\n        }\n        case OpenPgpApi.RESULT_CODE_ERROR: {\n            OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);\n            [...]\n            break;\n        }\n    }\n    ```\n\n4.  Results from a ``PendingIntent`` are returned in ``onActivityResult`` of the activity, which executed ``startIntentSenderForResult``.\n    The returned ``Intent data`` in ``onActivityResult`` contains the original PGP operation definition and new values acquired from the user interaction.\n    Thus, you can now execute the ``Intent`` again, like done in step 1.\n    This time it should return with ``RESULT_CODE_SUCCESS`` because all required information has been obtained by the previous user interaction stored in this ``Intent``.\n    ```java\n    protected void onActivityResult(int requestCode, int resultCode, Intent data) {\n        [...]\n        // try again after user interaction\n        if (resultCode == RESULT_OK) {\n            switch (requestCode) {\n                case 42: {\n                    encrypt(data); // defined like in step 1\n                    break;\n                }\n            }\n        }\n    }\n    ```\n\n\n### Tipps\n*   ``api.executeApi(data, is, os);`` is a blocking call. If you want a convenient asynchronous call, use ``api.executeApiAsync(data, is, os, new MyCallback([... ]));``, where ``MyCallback`` is an private class implementing ``OpenPgpApi.IOpenPgpCallback``.\n    See [``OpenPgpApiActivity.java``](https://github.com/open-keychain/openpgp-api/blob/master/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java) for an example.\n*   Using\n\n    ```java\n    mServiceConnection = new OpenPgpServiceConnection(this, \"org.sufficientlysecure.keychain\");\n    ```\n    connects to OpenKeychain directly.\n    If you want to let the user choose between OpenPGP providers, you can implement the [``OpenPgpAppPreference.java``](https://github.com/open-keychain/openpgp-api/tree/master/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpAppPreference.java) like done in the example app.\n\n*    To enable installing a debug and release version at the same time, the `debug` build of OpenKeychain uses `org.sufficientlysecure.keychain.debug` as a package name. Make sure you connect to the right one during development!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-keychain%2Fopenpgp-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopen-keychain%2Fopenpgp-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-keychain%2Fopenpgp-api/lists"}