quickstarts/cryptography/python/sdk
Kent (Chia-Hao), Hsu 42a99c20a4
add python-sdk in cryptography (#1093)
Signed-off-by: KentHsu <chiahaohsu9@gmail.com>
2025-01-14 09:24:16 -08:00
..
crypto-quickstart add python-sdk in cryptography (#1093) 2025-01-14 09:24:16 -08:00
README.md add python-sdk in cryptography (#1093) 2025-01-14 09:24:16 -08:00
makefile add python-sdk in cryptography (#1093) 2025-01-14 09:24:16 -08:00

README.md

Dapr cryptography (Dapr SDK)

In this quickstart, you'll create an application that encrypts, and then decrypts, data using the Dapr cryptography APIs (high-level). We will:

  • Encrypt and then decrypt a short string, reading the result in-memory
  • Encrypt and then decrypt a large file, storing the encrypted and decrypted data to files

Visit the documentation to learn more about the Cryptography building block in Dapr.

Note: This example uses the Dapr SDK. Using the Dapr SDK, which leverages gRPC internally, is strongly recommended when using the high-level cryptography APIs (to encrypt and decrypt messages).

This quickstart includes one application:

  • Python application crypto-quickstart

Run Python service with Dapr

In order to run this sample, make sure that OpenSSL is available on your system.

  1. Navigate into the folder with the source code:
cd ./crypto-quickstart
pip3 install -r requirements.txt
  1. This sample requires a private RSA key and a 256-bit symmetric (AES) key. We will generate them using OpenSSL:
mkdir -p keys
# Generate a private RSA key, 4096-bit keys
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -out keys/rsa-private-key.pem
# Generate a 256-bit key for AES
openssl rand -out keys/symmetric-key-256 32
  1. Run the Python service app with Dapr:
dapr run --app-id crypto-quickstart --resources-path ../../../components/ -- python3 app.py