CryptoSys Home > SC14N > Python

Python Interface to SC14N

A Python interface to SC14N for Windows. New2019-12-28 Released version 2.1.1 updated from Python 2 to Python 3.

Download and installation | Examples | Documentation | Contact

Download and installation

Automatic install from PyPi (recommended)

pip install sc14npy

Manual install

  1. Download the distribution file from the Python Package Index (PyPi).
  2. Open a command line console in the same directory as the zip file, then type
    pip install
    where "x.x.x" is the current version number.

Verify installation

>>> import sc14n
>>> sc14n.__version__
>>> sc14n.Gen.version()

where sc14n.__version__ is the Python package version and sc14n.Gen.version() is the version of the core SC14N DLL.

This requires Windows with Python 3 and the Windows program SC14N to be installed. SC14N can be downloaded from here.


The transformation can be of the complete document, a subset of the document, or the document excluding a given subset. The subset can be specified either by its ID or tag name. The following examples output the canonicalized data to text files.

>>> import sc14n
>>> # Example 1. Excludes the first element with the tag name <Signature>
>>> r = sc14n.C14n.file2file("c14nfile1.txt", "input.xml", "Signature", sc14n.Tran.OMITBYTAG)
>>> # Example 2. Finds and transforms the first element with the tag name <SignedInfo>
>>> r = sc14n.C14n.file2file("c14nfile2.txt", "input.xml", "SignedInfo", sc14n.Tran.SUBSETBYTAG)
>>> # Example 3. Finds and transforms the third element with the tag name <Data>
>>> r = sc14n.C14n.file2file("c14nfile3.txt", "input.xml", "Data[3]", sc14n.Tran.SUBSETBYTAG)
>>> # Example 4. Finds and transforms the element with attribute Id="foo"
>>> r = sc14n.C14n.file2file("c14nfile4.txt", "input.xml", "foo", sc14n.Tran.SUBSETBYID)
>>> # Example 5. Finds and transforms the element with attribute ID="bar"
>>> r = sc14n.C14n.file2file("c14nfile5.txt", "input.xml", "ID=bar", sc14n.Tran.SUBSETBYID)
>>> # Example 6. Excludes element with attribute Id="thesig"
>>> r = sc14n.C14n.file2file("c14nfile6.txt", "input.xml", "thesig", sc14n.Tran.OMITBYID)

Example Python program using SC14N

Some tests for the Python interface to SC14N.

Example Python program using SC14N and CryptoSys PKI

Some tests for the Python interface to SC14N using CryptoSys PKI..

The above two programs and the test files are in the distribution file available at the Python Package Index (PyPi).


Read the Sc14n Py documentation and the README document.


To comment on this page, make a suggestion for improvement, or just to say you liked it, please send us a message.

This page first published 12 July 2017. Last updated 30 July 2021.