Cipherion
Sdk IntegrationsPython SDK

Quick Start

Get started with Cipherion in 5 minutes

Quick Start

This guide will help you encrypt and decrypt your first data in minutes.

Prerequisites

Before starting, ensure you have:

  1. Created a Cipherion account
  2. Generated API credentials
  3. Installed the SDK

Step 1: Set Up Environment Variables

Create a .env file in your project root:

.env
CIPHERION_BASE_URL=https://api.cipherion.in
CIPHERION_PROJECT_ID=your-project-id
CIPHERION_API_KEY=your-api-key
CIPHERION_PASSPHRASE=your-secure-passphrase

Your passphrase must be at least 12 characters long

The examples below use the synchronous (sync) client. An async client is also available and follows the same usage with await.

Step 2: Initialize the Client

from cipherion import CipherionClient
import os

client = CipherionClient({
    "baseUrl": os.getenv("CIPHERION_BASE_URL"),
    "projectId": os.getenv("CIPHERION_PROJECT_ID"),
    "apiKey": os.getenv("CIPHERION_API_KEY"),
    "passphrase": os.getenv("CIPHERION_PASSPHRASE"),
})

Step 3: Encrypt Your First Data

Simple String Encryption

def encryptString():
    plaintext = "Hello, Cipherion!"
    encrypted = client.encrypt(plaintext)
    
    print('Encrypted:', encrypted)
    # Output: "encrypted_token,mapped_data,iv"

encryptString()

Complex Object Encryption

def encryptObject():
    userData = {
        "name": "John Doe",
        "email": "john@example.com",
        "phone": "+1234567890",
        "address": "123 Main St"
    }
    result = client.deep_encrypt(userData)
    
    print('Encrypted data:', result.encrypted)
    print('Total fields:', result.meta.totalFields)

encryptObject()

Step 4: Decrypt Data

def decryptData():
    # Decrypt simple string
    encrypted = "encrypted_token,mapped_data,iv"
    plaintext = client.decrypt(encrypted)
    print('Decrypted:', plaintext)
    
    # Decrypt complex object
    encryptedObject = {
        "name": "encrypted_...",
        "email": "encrypted_...",
        "phone": "encrypted_...",
        "address": "encrypted_..."
    }
    
    result = client.deep_decrypt(encryptedObject)
    print('Decrypted object:', result["data"])

decryptData()

Step 5: Handle Errors

from cipherion import CipherionError

def safeEncryption():
    try:
        encrypted = client.encrypt("sensitive data")
        print('Success:', encrypted)
    except CipherionError as error:
        print('Encryption failed:', error.getUserMessage())
        
    except Exception as error:
        print('Unexpected error:', error)

safeEncryption()

Complete Example

complete-example.py
from cipherion import CipherionClient, CipherionError
import os
from dotenv import load_dotenv

load_dotenv()

client = CipherionClient()

def main():
    try:
        # Encrypt user data
        user = {
            "id": "user_123",
            "name": "Alice Smith",
            "email": "alice@example.com",
            "ssn": "123-45-6789"
        }
        
        print('Original user:', user)
        
        # Encrypt, excluding the ID
        encrypted = client.deep_encrypt(user, 
            DeepEncryptOptions("exclude_fields": ["id"])
        )
        
        print('Encrypted user:', encrypted.encrypted)
        
        
        # Decrypt back
        decrypted = client.deepDecrypt(encrypted["encrypted"], 
            DeepDecryptOptions("exclude_fields": ["id"])
        )
        
        print('Decrypted user:', decrypted["data"])
        
    except CipherionError as error:
        print('Error:', error.getUserMessage())

main()

On this page