Implementing Cryptography Using Python

Wiley (Verlag)
  • 1. Auflage
  • |
  • erschienen am 20. Juli 2020
  • |
  • 304 Seiten
E-Book | ePUB mit Adobe-DRM | Systemvoraussetzungen
978-1-119-61545-3 (ISBN)
Learn to deploy proven cryptographic tools in your applications and services

Cryptography is, quite simply, what makes security and privacy in the digital world possible. Tech professionals, including programmers, IT admins, and security analysts, need to understand how cryptography works to protect users, data, and assets. Implementing Cryptography Using Python will teach you the essentials, so you can apply proven cryptographic tools to secure your applications and systems. Because this book uses Python, an easily accessible language that has become one of the standards for cryptography implementation, you'll be able to quickly learn how to secure applications and data of all kinds.

In this easy-to-read guide, well-known cybersecurity expert Shannon Bray walks you through creating secure communications in public channels using public-key cryptography. You'll also explore methods of authenticating messages to ensure that they haven't been tampered with in transit. Finally, you'll learn how to use digital signatures to let others verify the messages sent through your services.
* Learn how to implement proven cryptographic tools, using easy-to-understand examples written in Python
* Discover the history of cryptography and understand its critical importance in today's digital communication systems
* Work through real-world examples to understand the pros and cons of various authentication methods
* Protect your end-users and ensure that your applications and systems are using up-to-date cryptography
weitere Ausgaben werden ermittelt
SHANNON W. BRAY CASP, Security +, CISM is the Virtual CISO at Secured Systems providing clients guidance on establishing and maintaining information security plans, policies, procedures, standards, and guidelines using accepted frameworks. He has worked in this roles and others in corporations and federal agencies. Shannon has an MS in Cybersecurity from the University of Delaware. Prior to transitioning to cybersecurity, he was a well known IT expert with several successful books about Microsoft SharePoint.

Introduction to Cryptography and Python

Cryptography is one of the most important tools we have at our disposal as information security professionals. It provides us with the ability to protect sensitive information from unauthorized disclosure through encryption. Cryptography is the use of mathematical algorithms that can be used to transform data either into an encrypted form (ciphertext) or into its decrypted form (plaintext). The purpose of these algorithms can be quite complicated. The goal of this book is to help simplify the use of cryptography using the available libraries in Python, so you will begin your journey into cryptography by setting up a Python environment. You'll also get a review of using Python, and then you'll write your first cipher using Python. Specifically, you'll do the following:

  • Gain an understanding of algorithms
  • Explore various Python installations
  • Set up Python 3 on various machines
  • Explore the basics of the Python language
  • Write your first cipher using Python

Exploring Algorithms

The algorithms you will explore in this book can be quite sophisticated, but most of the logic is encapsulated into little black boxes that allow you to interface with the algorithms using functions. In the programming or mathematical world, a function is merely a way to enter values and receive output. When using algorithms in cryptography, we generally have two inputs for encryption and two inputs for decryption:

  • The encryption process will take the plaintext message (P) along with an encryption key (K) and then run the plaintext through encryption algorithms, which will return ciphertext (C).
  • On the decryption side, the ciphertext (C) will be supplied along with the encryption key (K), which will produce the plaintext (P) message.

As you study various encryption themes throughout this book, you will find that they are described by three algorithms: GEN for key generation, ENC for the encryption algorithm, and DEC for the decryption algorithm. You'll revisit this concept at the end of this chapter when you learn how to create a Python function.

Why Use Python?

Using Python for cryptography is simpler than using languages such as C or C++; while free libraries such as OpenSSL are available, their use can be quite complex. Python removes these complexities with many built-in libraries that aid in cryptography scripting. It is also a great choice because Python is free in terms of license. Python can be described as an open-source, general-purpose language that is object oriented, functional, and procedural, and it allows for the interface with C/ObjC/Java/Fortran and even .NET. A number of versions are available, from 2.5.x through 3.x. Currently, 3.x is becoming more popular as new libraries are introduced. Python comes preinstalled with Linux and macOS, and you can install it on Windows as well. You will learn how to install Python in each of these environments later in this chapter.

Because Python is available for Windows, Linux/Unix, Mac, and Chromebooks, among others, the lessons you learn here will be portable to several environments. Python has proven to be quite powerful in information security and can be used to quickly script solutions to help you become a better security practitioner. If you are using Ubuntu Linux, every command you see in this book will work. If you are on a Mac, you can use the Terminal app found inside the Utilities folder. On a Windows machine, you have several options as well: you can install a number of tools such as Cygwin, Visual Studio, or PyCharm; use the Windows 10 Linux subsystem; or just install Ubuntu Linux from the Microsoft Store. If you are new to Linux, I recommend practicing your command-line skills a bit to help get you comfortable.

When you start the Python shell (by typing python or python3 at the command line), you will see the version and the date associated with the version. For instance, if you install and run Python in a Linux environment, you should see something similar to the following:

Python 3.7.4+ (default, Sep 4 2019, 08:03:05) [GCC 9.2.1 20190827] on linux Type "help", "copyright", "credits" or "license" for more information. >>>

The majority of Python interpreters use >>> as a prompt to accept user input; one notable exception is IPython, which is discussed briefly in a moment. Once you are in a Python shell, exit by pressing CTRL+D or typing exit(). Python files use a .py extension, and we start their execution in Linux environments by typing python3; (keep in mind that you still need to chmod +x the file).

NOTE In Unix-like operating systems, the chmod command sets the permissions of files or directories.

As you will learn later in this chapter, a large number of modules are available for Python, many of which we will use along your journey of learning cryptography. One of the more notable modules you will learn more about is NumPy. NumPy offers numerical operations to Python, including fast multidimensional array operations, random number generation, and linear algebra. Another module that you will be introduced to is Matplotlib, which is an excellent library for plotting. In Chapter 6, you will learn more about PyFITS, which is a module that provides access to Flexible Image Transport System (FITS) files. FITS is a portable file standard that is widely used throughout the astronomy community to store images and tables. We will be combining it with our cryptography techniques to encrypt and decrypt image files.

Downloading and Installing Python

You can download the Python interpreter from, where you'll find versions for Ubuntu, macOS, and Windows. Be sure to download version 3.7 or higher, since Python 2 is now unsupported.

Installing on Ubuntu

If you are running Ubuntu, install Python from the Ubuntu Software Center using these steps:

  1. Open the Ubuntu Software Center.
  2. In the search box in the top-right corner of the window, type Python.
  3. Select IDLE.
  4. Click Install.

Installing on macOS

If you are using macOS, download the .dmg file for your version of macOS and execute it. When the DMG package opens, do the following:

  1. Double-click the Python package file ( .mpkg).
  2. Click Continue through the Welcome section and click Agree to accept the license.
  3. Select HD Macintosh and click Install.

Installing on Windows

If you are using Windows, download and run the Python installer; it should have an .msi extension. Then follow these steps:

  1. Click Install Now to begin the installation.
  2. When the installation completes, click Close.

Notice the mention of upgrading. You can upgrade a package by clearing out the Search PyPI and Installed Packages search box. This will show you all of the installed packages. Any package that has an update will have an up arrow next to it along with the newer version number (see Figure 1.1). You may have to elevate your privileges.

Installing on a Chromebook

New Windows and Chrome OS computers give you the ability to install Linux. The Chrome OS, which is becoming more popular, enables you to install a Linux container that you can interact with but also keeps the rest of the environment isolated so that you do not have to worry about messing up your system.

Figure 1.1: Upgrading packages

To get started with Python 3 on a Chromebook, click the time in the lower-right corner. If you have the appropriate permissions on the Chromebook, you should see a Settings button that looks like a flower with a dot in the middle of it. Once you are in Settings, you can scroll down until you find Linux (Beta) and then enable it by clicking Turn On. It may take several minutes, but once it is complete, you will be able to run Linux tools, editors, and IDEs on your Chromebook. To continue with the Chromebook installation, see the next section for instructions on how to install NumPy and Matplotlib.

Installing Additional Packages

Many of the coding recipes that you will find in this book require additional packages or modules to help reduce the amount of code you need to write to ensure message security. Most Python interpreters use a command-line approach of loading the packages. Integrated development environments (IDEs) may have unique ways of loading packages for each interpreter available.

Installing Pip, NumPy, and Matplotlib

Ensure you are in a command shell environment with a prompt. In the following example installation, you will get an update to the packages that come with your Python version.

Pip, or Pip3 in this case, is the package management system for Python; it is used to install and manage software packages written in Python. Pip is similar to tools like Bundle, NPM, and Composer in other programming languages. NumPy, which stands for Numerical Python, is a Python package that is the core library for scientific computing. It contains a powerful n-dimensional array object, and...

Dateiformat: ePUB
Kopierschutz: Adobe-DRM (Digital Rights Management)


Computer (Windows; MacOS X; Linux): Installieren Sie bereits vor dem Download die kostenlose Software Adobe Digital Editions (siehe E-Book Hilfe).

Tablet/Smartphone (Android; iOS): Installieren Sie bereits vor dem Download die kostenlose App Adobe Digital Editions (siehe E-Book Hilfe).

E-Book-Reader: Bookeen, Kobo, Pocketbook, Sony, Tolino u.v.a.m. (nicht Kindle)

Das Dateiformat ePUB ist sehr gut für Romane und Sachbücher geeignet - also für "fließenden" Text ohne komplexes Layout. Bei E-Readern oder Smartphones passt sich der Zeilen- und Seitenumbruch automatisch den kleinen Displays an. Mit Adobe-DRM wird hier ein "harter" Kopierschutz verwendet. Wenn die notwendigen Voraussetzungen nicht vorliegen, können Sie das E-Book leider nicht öffnen. Daher müssen Sie bereits vor dem Download Ihre Lese-Hardware vorbereiten.

Bitte beachten Sie bei der Verwendung der Lese-Software Adobe Digital Editions: wir empfehlen Ihnen unbedingt nach Installation der Lese-Software diese mit Ihrer persönlichen Adobe-ID zu autorisieren!

Weitere Informationen finden Sie in unserer E-Book Hilfe.

Download (sofort verfügbar)

32,99 €
inkl. 5% MwSt.
Download / Einzel-Lizenz
ePUB mit Adobe-DRM
siehe Systemvoraussetzungen
E-Book bestellen