Encryption
Encryption
Section titled “Encryption”Hyra Network employs AES encryption and asymmetric encryption using environment wallet public and private keys to ensure data security, privacy, and integrity across the distributed AI network.
Encryption Overview
Section titled “Encryption Overview”Encryption in Hyra Network serves multiple purposes:
- Data Confidentiality: Protect sensitive AI task data from unauthorized access
- Data Integrity: Ensure data hasn’t been tampered with during transmission
- Authentication: Verify the identity of data sources using wallet keys
- Privacy: Maintain user privacy in AI computations with end-to-end encryption
Encryption Types Used
Section titled “Encryption Types Used”1. AES Encryption (Symmetric)
Section titled “1. AES Encryption (Symmetric)”AES (Advanced Encryption Standard) is used for encrypting task input and output data:
# Example: AES encryption for task datafrom hyra_network.crypto import AESEncryption
# Initialize AES encryptionaes = AESEncryption(key_size=256)
# Encrypt task input dataencrypted_input = aes.encrypt(task_input_data, aes_key)print(f"Encrypted input: {encrypted_input}")
# Decrypt task input datadecrypted_input = aes.decrypt(encrypted_input, aes_key)print(f"Decrypted input: {decrypted_input}")// Example: AES encryption for task dataconst { AESEncryption } = require("@hyra-network/sdk");
// Initialize AES encryptionconst aes = new AESEncryption({ keySize: 256 });
// Encrypt task input dataconst encryptedInput = aes.encrypt(taskInputData, aesKey);console.log(`Encrypted input: ${encryptedInput}`);
// Decrypt task input dataconst decryptedInput = aes.decrypt(encryptedInput, aesKey);console.log(`Decrypted input: ${decryptedInput}`);AES Features:
- Key Sizes: AES-128, AES-192, AES-256
- Modes: CBC, GCM, CTR for different security requirements
- Performance: Fast encryption/decryption for large data
- Security: Military-grade encryption standard
2. Asymmetric Encryption (RSA/ECC)
Section titled “2. Asymmetric Encryption (RSA/ECC)”Asymmetric encryption using environment wallet public and private keys:
# Example: Asymmetric encryption with wallet keysfrom hyra_network.crypto import AsymmetricEncryptionimport os
# Get wallet keys from environmentprivate_key = os.getenv('WALLET_PRIVATE_KEY')public_key = os.getenv('WALLET_PUBLIC_KEY')
# Initialize asymmetric encryptioncrypto = AsymmetricEncryption()
# Encrypt data with recipient's public keyencrypted_data = crypto.encrypt(data, recipient_public_key)
# Decrypt data with your private keydecrypted_data = crypto.decrypt(encrypted_data, private_key)// Example: Asymmetric encryption with wallet keysconst { AsymmetricEncryption } = require("@hyra-network/sdk");
// Get wallet keys from environmentconst privateKey = process.env.WALLET_PRIVATE_KEY;const publicKey = process.env.WALLET_PUBLIC_KEY;
// Initialize asymmetric encryptionconst crypto = new AsymmetricEncryption();
// Encrypt data with recipient's public keyconst encryptedData = crypto.encrypt(data, recipientPublicKey);
// Decrypt data with your private keyconst decryptedData = crypto.decrypt(encryptedData, privateKey);Asymmetric Encryption Features:
- RSA: Rivest-Shamir-Adleman algorithm for key exchange
- ECC: Elliptic Curve Cryptography for better performance
- Key Pairs: Public/private key pairs from wallet
- Digital Signatures: Verify data authenticity
Encryption in AI Context
Section titled “Encryption in AI Context”Task Input Encryption
Section titled “Task Input Encryption”Encrypt AI task input data before submission to smart contracts:
# Example: Encrypt task input datafrom hyra_network.crypto import TaskEncryption
# Initialize task encryptiontask_crypto = TaskEncryption()
# Encrypt task input with AESaes_key = task_crypto.generate_aes_key()encrypted_input = task_crypto.encrypt_input(task_input, aes_key)
# Wrap AES key with recipient's public keywrapped_key = task_crypto.wrap_aes_key(aes_key, recipient_public_key)
# Store encrypted data and wrapped keyencrypted_task = { 'encrypted_data': encrypted_input, 'wrapped_key': wrapped_key}// Example: Encrypt task input dataconst { TaskEncryption } = require("@hyra-network/sdk");
// Initialize task encryptionconst taskCrypto = new TaskEncryption();
// Encrypt task input with AESconst aesKey = taskCrypto.generateAESKey();const encryptedInput = taskCrypto.encryptInput(taskInput, aesKey);
// Wrap AES key with recipient's public keyconst wrappedKey = taskCrypto.wrapAESKey(aesKey, recipientPublicKey);
// Store encrypted data and wrapped keyconst encryptedTask = { encryptedData: encryptedInput, wrappedKey: wrappedKey,};Task Output Encryption
Section titled “Task Output Encryption”Encrypt AI task output data before submission:
# Example: Encrypt task output datafrom hyra_network.crypto import OutputEncryption
# Initialize output encryptionoutput_crypto = OutputEncryption()
# Encrypt task output with AESaes_key = output_crypto.generate_aes_key()encrypted_output = output_crypto.encrypt_output(task_output, aes_key)
# Wrap AES key for multiple recipientswrapped_keys = { 'verifier': output_crypto.wrap_aes_key(aes_key, verifier_public_key), 'user': output_crypto.wrap_aes_key(aes_key, user_public_key), 'worker': output_crypto.wrap_aes_key(aes_key, worker_public_key)}
# Store encrypted output and wrapped keysencrypted_result = { 'encrypted_output': encrypted_output, 'wrapped_keys': wrapped_keys}// Example: Encrypt task output dataconst { OutputEncryption } = require("@hyra-network/sdk");
// Initialize output encryptionconst outputCrypto = new OutputEncryption();
// Encrypt task output with AESconst aesKey = outputCrypto.generateAESKey();const encryptedOutput = outputCrypto.encryptOutput(taskOutput, aesKey);
// Wrap AES key for multiple recipientsconst wrappedKeys = { verifier: outputCrypto.wrapAESKey(aesKey, verifierPublicKey), user: outputCrypto.wrapAESKey(aesKey, userPublicKey), worker: outputCrypto.wrapAESKey(aesKey, workerPublicKey),};
// Store encrypted output and wrapped keysconst encryptedResult = { encryptedOutput: encryptedOutput, wrappedKeys: wrappedKeys,};Cryptographic Algorithms
Section titled “Cryptographic Algorithms”AES (Advanced Encryption Standard)
Section titled “AES (Advanced Encryption Standard)”AES-256-GCM (Recommended)
Section titled “AES-256-GCM (Recommended)”# Example: AES-256-GCM encryptionfrom hyra_network.crypto import AES256GCM
aes = AES256GCM()encrypted_data, auth_tag = aes.encrypt(data, key, nonce)decrypted_data = aes.decrypt(encrypted_data, key, nonce, auth_tag)Features:
- 256-bit key length: Maximum security
- GCM mode: Authenticated encryption
- Nonce: Unique nonce for each encryption
- Authentication: Built-in integrity verification
AES-128-CBC (Legacy)
Section titled “AES-128-CBC (Legacy)”# Example: AES-128-CBC encryptionfrom hyra_network.crypto import AES128CBC
aes = AES128CBC()encrypted_data = aes.encrypt(data, key, iv)decrypted_data = aes.decrypt(encrypted_data, key, iv)Features:
- 128-bit key length: Good security
- CBC mode: Cipher Block Chaining
- IV: Initialization Vector for each encryption
- Compatibility: Widely supported
Asymmetric Encryption
Section titled “Asymmetric Encryption”RSA Encryption
Section titled “RSA Encryption”# Example: RSA encryptionfrom hyra_network.crypto import RSAEncryption
rsa = RSAEncryption(key_size=2048)public_key, private_key = rsa.generate_keypair()encrypted_data = rsa.encrypt(data, public_key)decrypted_data = rsa.decrypt(encrypted_data, private_key)Features:
- 2048-bit key length: Strong security
- Key Exchange: Secure key distribution
- Digital Signatures: Data authenticity
- Widely Supported: Standard algorithm
ECC Encryption
Section titled “ECC Encryption”# Example: ECC encryptionfrom hyra_network.crypto import ECCEncryption
ecc = ECCEncryption(curve='secp256k1')public_key, private_key = ecc.generate_keypair()encrypted_data = ecc.encrypt(data, public_key)decrypted_data = ecc.decrypt(encrypted_data, private_key)Features:
- secp256k1 curve: Bitcoin-compatible
- Smaller keys: More efficient than RSA
- Better performance: Faster encryption/decryption
- Mobile friendly: Lower computational requirements
Key Management
Section titled “Key Management”Environment Key Configuration
Section titled “Environment Key Configuration”Python Environment Setup
Section titled “Python Environment Setup”# Example: Environment key configurationimport osfrom hyra_network.crypto import KeyManager
# Set environment variablesos.environ['WALLET_PRIVATE_KEY'] = 'your_private_key_here'os.environ['WALLET_PUBLIC_KEY'] = 'your_public_key_here'
# Initialize key managerkey_manager = KeyManager()
# Get keys from environmentprivate_key = key_manager.get_private_key()public_key = key_manager.get_public_key()Node.js Environment Setup
Section titled “Node.js Environment Setup”// Example: Environment key configurationconst { KeyManager } = require("@hyra-network/sdk");
// Set environment variablesprocess.env.WALLET_PRIVATE_KEY = "your_private_key_here";process.env.WALLET_PUBLIC_KEY = "your_public_key_here";
// Initialize key managerconst keyManager = new KeyManager();
// Get keys from environmentconst privateKey = keyManager.getPrivateKey();const publicKey = keyManager.getPublicKey();Key Generation
Section titled “Key Generation”Generate New Key Pairs
Section titled “Generate New Key Pairs”# Example: Generate new key pairsfrom hyra_network.crypto import KeyGenerator
keygen = KeyGenerator()
# Generate RSA key pairrsa_public, rsa_private = keygen.generate_rsa_keypair(2048)
# Generate ECC key pairecc_public, ecc_private = keygen.generate_ecc_keypair('secp256k1')
# Generate AES keyaes_key = keygen.generate_aes_key(256)// Example: Generate new key pairsconst { KeyGenerator } = require("@hyra-network/sdk");
const keygen = new KeyGenerator();
// Generate RSA key pairconst { publicKey: rsaPublic, privateKey: rsaPrivate } = keygen.generateRSAKeyPair(2048);
// Generate ECC key pairconst { publicKey: eccPublic, privateKey: eccPrivate } = keygen.generateECCKeyPair("secp256k1");
// Generate AES keyconst aesKey = keygen.generateAESKey(256);Key Storage
Section titled “Key Storage”Secure Key Storage
Section titled “Secure Key Storage”# Example: Secure key storagefrom hyra_network.crypto import SecureKeyStorage
storage = SecureKeyStorage()
# Store keys securelystorage.store_key('wallet_private', private_key, encrypted=True)storage.store_key('wallet_public', public_key, encrypted=False)
# Retrieve keysretrieved_private = storage.retrieve_key('wallet_private')retrieved_public = storage.retrieve_key('wallet_public')// Example: Secure key storageconst { SecureKeyStorage } = require("@hyra-network/sdk");
const storage = new SecureKeyStorage();
// Store keys securelystorage.storeKey("wallet_private", privateKey, { encrypted: true });storage.storeKey("wallet_public", publicKey, { encrypted: false });
// Retrieve keysconst retrievedPrivate = storage.retrieveKey("wallet_private");const retrievedPublic = storage.retrieveKey("wallet_public");Security Considerations
Section titled “Security Considerations”Key Security
Section titled “Key Security”Key Length Requirements
Section titled “Key Length Requirements”- AES: Minimum 128-bit, recommended 256-bit
- RSA: Minimum 2048-bit, recommended 4096-bit
- ECC: Minimum 256-bit, recommended 384-bit
Key Randomness
Section titled “Key Randomness”# Example: Ensure cryptographic randomnessfrom hyra_network.crypto import SecureRandom
secure_random = SecureRandom()
# Generate cryptographically secure random keyrandom_key = secure_random.generate_key(256)print(f"Random key: {random_key.hex()}")// Example: Ensure cryptographic randomnessconst { SecureRandom } = require("@hyra-network/sdk");
const secureRandom = new SecureRandom();
// Generate cryptographically secure random keyconst randomKey = secureRandom.generateKey(256);console.log(`Random key: ${randomKey.toString("hex")}`);Algorithm Security
Section titled “Algorithm Security”Algorithm Selection
Section titled “Algorithm Selection”- AES-256-GCM: For symmetric encryption
- RSA-2048: For key exchange and signatures
- ECC-secp256k1: For efficient asymmetric operations
- SHA-256: For hashing and integrity
Implementation Security
Section titled “Implementation Security”# Example: Secure implementationfrom hyra_network.crypto import SecureImplementation
secure_impl = SecureImplementation()
# Use secure random noncesnonce = secure_impl.generate_secure_nonce()
# Use authenticated encryptionencrypted_data, auth_tag = secure_impl.encrypt_authenticated(data, key, nonce)// Example: Secure implementationconst { SecureImplementation } = require("@hyra-network/sdk");
const secureImpl = new SecureImplementation();
// Use secure random noncesconst nonce = secureImpl.generateSecureNonce();
// Use authenticated encryptionconst { encryptedData, authTag } = secureImpl.encryptAuthenticated( data, key, nonce);Performance Optimization
Section titled “Performance Optimization”Hardware Acceleration
Section titled “Hardware Acceleration”AES-NI Support
Section titled “AES-NI Support”# Example: Hardware-accelerated AESfrom hyra_network.crypto import HardwareAES
hardware_aes = HardwareAES()encrypted_data = hardware_aes.encrypt(data, key) # Uses AES-NI if available// Example: Hardware-accelerated AESconst { HardwareAES } = require("@hyra-network/sdk");
const hardwareAES = new HardwareAES();const encryptedData = hardwareAES.encrypt(data, key); // Uses AES-NI if availableBatch Processing
Section titled “Batch Processing”Encrypt Multiple Data
Section titled “Encrypt Multiple Data”# Example: Batch encryptionfrom hyra_network.crypto import BatchEncryption
batch_crypto = BatchEncryption()
# Encrypt multiple data itemsdata_items = [data1, data2, data3]encrypted_items = batch_crypto.encrypt_batch(data_items, key)// Example: Batch encryptionconst { BatchEncryption } = require("@hyra-network/sdk");
const batchCrypto = new BatchEncryption();
// Encrypt multiple data itemsconst dataItems = [data1, data2, data3];const encryptedItems = batchCrypto.encryptBatch(dataItems, key);Compliance and Standards
Section titled “Compliance and Standards”Industry Standards
Section titled “Industry Standards”- FIPS 140-2: Federal Information Processing Standard
- Common Criteria: International security standard
- ISO 27001: Information security management
Regulatory Compliance
Section titled “Regulatory Compliance”- GDPR: General Data Protection Regulation
- HIPAA: Health Insurance Portability and Accountability Act
- SOX: Sarbanes-Oxley Act
Future Developments
Section titled “Future Developments”Post-Quantum Cryptography
Section titled “Post-Quantum Cryptography”Prepare for quantum computing threats:
- Lattice-Based: Lattice-based cryptography
- Code-Based: Code-based cryptography
- Hash-Based: Hash-based signatures
Advanced Encryption
Section titled “Advanced Encryption”- Fully Homomorphic: Complete homomorphic encryption
- Multi-Party: Secure multi-party computation
- Functional: Functional encryption schemes
Resources
Section titled “Resources”- Encryption Documentation: docs.hyra.network/encryption
- Security Best Practices: docs.hyra.network/security
- GitHub: github.com/hyra-network
- Discord: discord.gg/hyra
Next Steps
Section titled “Next Steps”Ready to implement encryption in your applications? Check out our guides:
- Two-Phase Encryption - Learn about our advanced encryption system
- Getting Started - Set up your development environment
- SDKs - Use our development tools