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 v23.0 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
230000
>>> pki.__version__   # cryptosyspki.py package
'23.0.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.

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
23 September 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-23.0.0.tar.gz (256.0 kB view details)

Uploaded Source

File details

Details for the file cryptosyspki-23.0.0.tar.gz.

File metadata

  • Download URL: cryptosyspki-23.0.0.tar.gz
  • Upload date:
  • Size: 256.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for cryptosyspki-23.0.0.tar.gz
Algorithm Hash digest
SHA256 74ce2e39a3683cf2374237a53b80986b9a47afbdeb73e3e93c7d4c56f1650d79
MD5 38038a11e37256478ae88849148be393
BLAKE2b-256 e829d5f49231eb93cd58429e6f3d28da98a88a9fdb777088de0b26a28ebae79b

See more details on using hashes here.

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