Overview
TheHelperCryptography class provides cryptographic utilities for hashing sensitive data like passwords. It offers both basic and advanced encryption methods with comparison capabilities.
Encryption Methods
Basic Encryption (SHA1)
Simple SHA1-based encryption suitable for basic hashing needs.Efficient Encryption (SHA512 + Salt)
Advanced encryption using SHA512 with randomly generated salt, iterated 12 times for enhanced security.Complete Implementation
Create the Cryptography Helper
The See HelperCryptography.cs:24 and HelperCryptography.cs:45
HelperCryptography class provides static methods for encryption.Helpers/HelperCryptography.cs
Create the Controller
The controller handles both encryption methods with encrypt and compare actions.See CifradosController.cs:24 and CifradosController.cs:48
Controllers/CifradosController.cs
How It Works
Basic Encryption Workflow
- Encrypt: Enter text → Click “Cifrar contenido” → Get SHA1 hash
- Compare: Enter original text → Paste encrypted result → Click “Comparar cifrado” → Verify match
Efficient Encryption Workflow
- Encrypt: Enter text → Click “Cifrar contenido” → Get SHA512 hash + Salt displayed
- Store Salt: Save the displayed salt (red text) - required for comparison
- Compare: Enter original text → Paste encrypted result → Click “Comparar cifrado” → Uses same salt to verify
Key Differences
Basic Encryption (SHA1)
Basic Encryption (SHA1)
- Algorithm: SHA1
- Salt: None
- Iterations: 1
- Security: Basic
- Use Case: Simple hashing, checksums
- Same input always produces same output
Efficient Encryption (SHA512 + Salt)
Efficient Encryption (SHA512 + Salt)
- Algorithm: SHA512
- Salt: 30-character random string
- Iterations: 12 (repeated hashing)
- Security: Enhanced
- Use Case: Password hashing, sensitive data
- Same input produces different output each time (due to random salt)
Important Security Notes
For production password hashing, consider using:
BCryptorArgon2instead of custom implementations- Built-in ASP.NET Core Identity password hashers
- These provide industry-standard security
Usage Examples
Encrypting a Password
Comparing a Password
Related
HelperCryptography
Complete API reference for encryption methods
Controllers
CifradosController API reference