Skip to main content

Python interface to CryptoSys PKI

Project description

This is a Python interface to the CryptoSys PKI Pro library.

CryptoSys PKI Pro is a library to carry out public key cryptography using RSA and ECDSA. You can generate and manage X.509 certificates, PKCS#8/PKCS#12 private keys and CMS/PKCS#7 objects. It includes all required supporting cryptographic utilities.

CryptoSys PKI Pro v22.1 or above must be installed on your system. This is available from

https://www.cryptosys.net/pki/.

To use in Python’s REPL

>>> from cryptosyspki import *
>>> Gen.version() # "hello world!" for CryptoSys PKI
220100
>>> Hash.hex_from_data(b'abc') # compute SHA-1 hash in hex of 'abc' as bytes
'a9993e364706816aba3e25717850c26c9cd0d89d'
>>> Hash.hex_from_string('abc', Hash.Alg.SHA256)   # same but over a string and using SHA-256
'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
>>> h = Hash.data(b'abc')   # h is a byte array (bytes->bytes)
>>> print(Cnv.tohex(h))     # display the byte array in hex
A9993E364706816ABA3E25717850C26C9CD0D89D

If you don’t like import * and find cryptosyspki a bit long to type each time, try

>>> import cryptosyspki as pki
>>> pki.Gen.version() #  Underlying core PKI dll
220100
>>> pki.__version__   # cryptosyspki.py package
'22.1.00.0000'

Examples

There is a series of tests in test_pki.py (source). You should find an example there of what you want to do.

These tests require a subdirectory work in the same folder which must contain all the required test files. A spare set of these test files is available separately in pkiPythonTestFiles.zip

test
|   test_pki.py
|
\---work
    |   <...all required test files>
    |
    \---tmp.XXXXXXXX
            <..temporary files...>

The test function creates a new temporary subdirectory each time, which is deleted automatically. If you want to keep this temp folder for debugging, then add the argument nodelete on the command line.

This structure is already set up in the distribution file, so unzip the file cryptosyspki-x.x.x.zip and open a command-line prompt in the test subdirectory. You can do any of the following.

  1. python test_pki.py

  2. py.test -v

  3. Open the file test_pki.py using IDLE and select Run > Run Module (F5).

We’ve tested this using the Python 3.12.0 interpreter and IDLE, PyCharm 2023.2.3, and py.test 7.4.2.

post1 Update

2023-01-08: Updated distribution to use pyproject.toml and build instead of setup.py, and removed troublesome and unnecessary requirements file (which messed up pytest).

Contact

For more information or to make suggestions, please contact us at https://www.cryptosys.net/contact/

David Ireland
DI Management Services Pty Ltd
Australia
8 January 2024

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cryptosyspki-22.1.0.post1.tar.gz (237.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page