Site icon Python GUI

Learn To Integrate Python Cryptographic Services To A Delphi Windows GUI App

pexels tima miroshnichenko 5380590

Python offers various built-in algorithms for cryptographic tasks. On Unix systems, the crypt module may also be available. This post will demonstrate hashlib: One of the built-in algorithms for cryptographic tasks, used for secure hashes and message digests using Python and run it in the Python GUI by Python4Delphi to get the results.

hashlib implements a common interface to many different secure hash and message digest algorithms. Included are the FIPS secure hash algorithms SHA1, SHA224, SHA256, SHA384, and SHA512 (defined in FIPS 180-2) as well as RSA’s MD5 algorithm (defined in Internet RFC 1321). 

The terms “secure hash” and “message digest” are interchangeable. Older algorithms were called message digests. The modern term is secure hash.

This post will guide you on implementing Python cryptographic services using the built-in hashlib library in Python GUI for Delphi Windows App.

Prerequisites: Before we begin to work, download and install the latest Python for your platform. Follow the Python4Delphi installation instructions mentioned here. Alternatively, you can check out the easy instructions found in this video Getting started with Python4Delphi.

First, open and run our Python GUI using project Demo1 from Python4Delphi with RAD Studio. Then insert the script into the lower Memo, click the Execute button, and get the result in the upper Memo. You can find the Demo1 source on GitHub. The behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this link.

Open Demo01.dproj

 

1. Python hashlib Module

The hashlib module defines an API for accessing different cryptographic hashing algorithms. To work with a specific hash algorithm, use the appropriate constructor function or new() to create a hash object. From there, the objects use the same API, no matter what algorithm is being used.

Since hashlib is “backed” by OpenSSL, all of the algorithms provided by that library are available, including:

Some algorithms are available on all platforms, and some depend on the underlying libraries. For lists of each, look at algorithms_guaranteed and algorithms_available respectively using the following code:

[crayon-662be2e43f532123322746/]

See the results in our P4D GUI:

 

2. Example

Let’s try another example, to obtain the digest of the byte string b’Hello World!’, it’s more condensed version, and try an algorithm provided by OpenSSL:

[crayon-662be2e43f53f100002054/]

See the results in our P4D GUI:

Here are more details on hashlib methods:

 

Congratulations! You have learned how to implement Python cryptographic services using the built-in hashlib library in Python GUI for Delphi Windows App.

Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi.

Exit mobile version