keyprotect


Namekeyprotect JSON
Version 2.3.0 PyPI version JSON
download
home_pagehttps://github.com/IBM/keyprotect-python-client
SummaryA Pythonic client for IBM Key Protect
upload_time2024-06-12 19:40:42
maintainerNone
docs_urlNone
authorMathew Odden
requires_python>=3.5
licenseApache 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # IBM Cloud Python SDK Version 2.2.1

# keyprotect-python-client

[![PyPi](https://img.shields.io/pypi/v/keyprotect.svg)](https://pypi.org/project/keyprotect)
[![Downloads](https://static.pepy.tech/personalized-badge/ibmcloud-iam?period=total&units=international_system&left_color=grey&right_color=orange&left_text=Downloads)](https://pepy.tech/project/keyprotect)
[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0)
[![Build Status](https://travis-ci.com/IBM/keyprotect-python-client.svg?branch=master)](https://travis-ci.com/IBM/keyprotect-python-client)

A Pythonic client for IBM Key Protect

This is a thin wrapper around the KeyProtect client in the [redstone](https://github.com/IBM/redstone) Python package. For detailed documentation and API references, please see the [redstone docs](https://redstone-py.readthedocs.org)

The client works with Python 3.5 or higher

# Installation

The client is available on PyPI as the `keyprotect` package and is installable via `pip`:

```sh
pip install -U keyprotect
```

# Usage

The following python is a quick example of how to use the keyprotect module.

The example expects `IBMCLOUD_API_KEY` to be set to a valid IAM API key,
and `KP_INSTANCE_ID` to be set to the UUID identifying your KeyProtect instance.

```python
import os

import keyprotect
from keyprotect import bxauth


tm = bxauth.TokenManager(api_key=os.getenv("IBMCLOUD_API_KEY"))

kp = keyprotect.Client(
    credentials=tm,
    region="us-south",
    service_instance_id=os.getenv("KP_INSTANCE_ID")
)

for key in kp.keys():
    print("%s\t%s" % (key["id"], key["name"]))

key = kp.create(name="MyTestKey")
print("Created key '%s'" % key['id'])

kp.delete(key_id=key.get('id'))
print("Deleted key '%s'" % key['id'])


# wrap and unwrap require a non-exportable key,
# these are also referred to as root keys
key = kp.create(name="MyRootKey", root=True)

# wrap/unwrap, payload should be a bytestring if python3
message = b'This is a really important message.'
wrapped = kp.wrap(key_id=key.get('id'), plaintext=message)
ciphertext = wrapped.get("ciphertext")

unwrapped = kp.unwrap(key_id=key.get('id'), ciphertext=ciphertext)
assert message == unwrapped

# wrap/unwrap with AAD
message = b'This is a really important message too.'
wrapped = kp.wrap(key_id=key.get('id'), plaintext=message, aad=['python-keyprotect'])
ciphertext = wrapped.get("ciphertext")

unwrapped = kp.unwrap(key_id=key.get('id'), ciphertext=ciphertext, aad=['python-keyprotect'])
assert message == unwrapped
```

## Using custom endpoint (for HPCS, Private Endpoint, Satellite, and Stage/Test instances)

Custom endpoints are needed when using this Python client against an HPCS/Satellite/Private service instance.

The following example shows how to specify a custom service endpoint

```python
kp = keyprotect.Client(
    credentials=tm,
    region="<region>",
    service_instance_id=os.getenv("KP_INSTANCE_ID"),
    # Set custom service endpoint
    endpoint_url="https://private.us-south.kms.cloud.ibm.com"
)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/IBM/keyprotect-python-client",
    "name": "keyprotect",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": null,
    "keywords": null,
    "author": "Mathew Odden",
    "author_email": "mathewrodden@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/55/68/6957617045e7a81eb202d22bf1ab94e0e40215cd47a9393557eb0469b3ca/keyprotect-2.3.0.tar.gz",
    "platform": null,
    "description": "# IBM Cloud Python SDK Version 2.2.1\n\n# keyprotect-python-client\n\n[![PyPi](https://img.shields.io/pypi/v/keyprotect.svg)](https://pypi.org/project/keyprotect)\n[![Downloads](https://static.pepy.tech/personalized-badge/ibmcloud-iam?period=total&units=international_system&left_color=grey&right_color=orange&left_text=Downloads)](https://pepy.tech/project/keyprotect)\n[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0)\n[![Build Status](https://travis-ci.com/IBM/keyprotect-python-client.svg?branch=master)](https://travis-ci.com/IBM/keyprotect-python-client)\n\nA Pythonic client for IBM Key Protect\n\nThis is a thin wrapper around the KeyProtect client in the [redstone](https://github.com/IBM/redstone) Python package. For detailed documentation and API references, please see the [redstone docs](https://redstone-py.readthedocs.org)\n\nThe client works with Python 3.5 or higher\n\n# Installation\n\nThe client is available on PyPI as the `keyprotect` package and is installable via `pip`:\n\n```sh\npip install -U keyprotect\n```\n\n# Usage\n\nThe following python is a quick example of how to use the keyprotect module.\n\nThe example expects `IBMCLOUD_API_KEY` to be set to a valid IAM API key,\nand `KP_INSTANCE_ID` to be set to the UUID identifying your KeyProtect instance.\n\n```python\nimport os\n\nimport keyprotect\nfrom keyprotect import bxauth\n\n\ntm = bxauth.TokenManager(api_key=os.getenv(\"IBMCLOUD_API_KEY\"))\n\nkp = keyprotect.Client(\n    credentials=tm,\n    region=\"us-south\",\n    service_instance_id=os.getenv(\"KP_INSTANCE_ID\")\n)\n\nfor key in kp.keys():\n    print(\"%s\\t%s\" % (key[\"id\"], key[\"name\"]))\n\nkey = kp.create(name=\"MyTestKey\")\nprint(\"Created key '%s'\" % key['id'])\n\nkp.delete(key_id=key.get('id'))\nprint(\"Deleted key '%s'\" % key['id'])\n\n\n# wrap and unwrap require a non-exportable key,\n# these are also referred to as root keys\nkey = kp.create(name=\"MyRootKey\", root=True)\n\n# wrap/unwrap, payload should be a bytestring if python3\nmessage = b'This is a really important message.'\nwrapped = kp.wrap(key_id=key.get('id'), plaintext=message)\nciphertext = wrapped.get(\"ciphertext\")\n\nunwrapped = kp.unwrap(key_id=key.get('id'), ciphertext=ciphertext)\nassert message == unwrapped\n\n# wrap/unwrap with AAD\nmessage = b'This is a really important message too.'\nwrapped = kp.wrap(key_id=key.get('id'), plaintext=message, aad=['python-keyprotect'])\nciphertext = wrapped.get(\"ciphertext\")\n\nunwrapped = kp.unwrap(key_id=key.get('id'), ciphertext=ciphertext, aad=['python-keyprotect'])\nassert message == unwrapped\n```\n\n## Using custom endpoint (for HPCS, Private Endpoint, Satellite, and Stage/Test instances)\n\nCustom endpoints are needed when using this Python client against an HPCS/Satellite/Private service instance.\n\nThe following example shows how to specify a custom service endpoint\n\n```python\nkp = keyprotect.Client(\n    credentials=tm,\n    region=\"<region>\",\n    service_instance_id=os.getenv(\"KP_INSTANCE_ID\"),\n    # Set custom service endpoint\n    endpoint_url=\"https://private.us-south.kms.cloud.ibm.com\"\n)\n```\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "A Pythonic client for IBM Key Protect",
    "version": "2.3.0",
    "project_urls": {
        "Homepage": "https://github.com/IBM/keyprotect-python-client"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "67d74d988f17a9c03865d78b020cdfd13e72a141612754123b7120081bc7c700",
                "md5": "354c6e8974bb95687f6703c24ef0724c",
                "sha256": "e824d7de1592fc53b1e5e059916c4c745bed4c22d10c3a1ded22deb9de7e6cda"
            },
            "downloads": -1,
            "filename": "keyprotect-2.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "354c6e8974bb95687f6703c24ef0724c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.5",
            "size": 6990,
            "upload_time": "2024-06-12T19:40:40",
            "upload_time_iso_8601": "2024-06-12T19:40:40.805118Z",
            "url": "https://files.pythonhosted.org/packages/67/d7/4d988f17a9c03865d78b020cdfd13e72a141612754123b7120081bc7c700/keyprotect-2.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "55686957617045e7a81eb202d22bf1ab94e0e40215cd47a9393557eb0469b3ca",
                "md5": "1243d9defd3b6072ec206dfa394ad83a",
                "sha256": "33096aee42bd53968da31dc40f29c48cf9e0b45df2f381f875bd79a8701ae21c"
            },
            "downloads": -1,
            "filename": "keyprotect-2.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1243d9defd3b6072ec206dfa394ad83a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 6773,
            "upload_time": "2024-06-12T19:40:42",
            "upload_time_iso_8601": "2024-06-12T19:40:42.258487Z",
            "url": "https://files.pythonhosted.org/packages/55/68/6957617045e7a81eb202d22bf1ab94e0e40215cd47a9393557eb0469b3ca/keyprotect-2.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-12 19:40:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "IBM",
    "github_project": "keyprotect-python-client",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "tox": true,
    "lcname": "keyprotect"
}
        
Elapsed time: 0.25235s