Encrypt & Decrypt Text

Securely encrypt and decrypt text using various cryptographic algorithms

About Encryption

Encryption is the process of converting information into a code to prevent unauthorized access. It's a fundamental technique for securing sensitive data in transit and at rest.

Key concepts in encryption:

  • Symmetric Encryption: Uses the same key for both encryption and decryption. All algorithms in this tool are symmetric encryption algorithms.
  • Key: A piece of information that determines the output of the encryption algorithm. Keep your encryption keys secure and never share them publicly.
  • Cipher: The algorithm that performs the encryption and decryption. Different ciphers have different security properties and performance characteristics.
  • Initialization Vector (IV): A random value used along with the key to ensure that encrypting the same text multiple times produces different outputs.

Security Note: While this tool uses strong encryption algorithms, remember that the security of your encrypted data depends on keeping your encryption key secure. For highly sensitive information, consider using specialized security software.

Encryption Algorithm Comparison

Different encryption algorithms offer varying levels of security, performance, and compatibility. Here's a comparison of the algorithms available in this tool:

AlgorithmKey SizeSecurity LevelSpeedBest For
AES128, 192, or 256 bitsVery HighFastGeneral purpose encryption, sensitive data
DES56 bitsLow (considered broken)ModerateLegacy systems only (not recommended for new applications)
Triple DES168 bitsModerateSlowLegacy financial systems, compatibility with older standards
Rabbit128 bitsHighVery FastApplications requiring high-speed encryption
RC440 to 2048 bitsLow (vulnerabilities known)Very FastNot recommended for new applications

Example: Encrypting with AES

Here's an example of encrypting and decrypting text using AES in different programming languages:

JavaScript (using CryptoJS):


// Encrypt
const CryptoJS = require('crypto-js');
const plainText = "Hello World";
const key = "mySecretKey123";
const encrypted = CryptoJS.AES.encrypt(plainText, key).toString();
// Result: "U2FsdGVkX1+A8GpFfQDSZcLLXa8bGOVtH66EuUTzL6M="

// Decrypt
const decrypted = CryptoJS.AES.decrypt(encrypted, key).toString(CryptoJS.enc.Utf8);
// Result: "Hello World"
                

Python (using pycryptodome):


from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
from Crypto.Random import get_random_bytes
import base64

# Encrypt
def encrypt(plain_text, key):
    key = key.encode('utf-8')
    key = key.ljust(32)[:32]  # Ensure key is 32 bytes
    iv = get_random_bytes(16)
    cipher = AES.new(key, AES.MODE_CBC, iv)
    ct_bytes = cipher.encrypt(pad(plain_text.encode('utf-8'), AES.block_size))
    return base64.b64encode(iv + ct_bytes).decode('utf-8')

# Decrypt
def decrypt(encrypted_text, key):
    key = key.encode('utf-8')
    key = key.ljust(32)[:32]  # Ensure key is 32 bytes
    encrypted_bytes = base64.b64decode(encrypted_text)
    iv = encrypted_bytes[:16]
    ct = encrypted_bytes[16:]
    cipher = AES.new(key, AES.MODE_CBC, iv)
    pt = unpad(cipher.decrypt(ct), AES.block_size)
    return pt.decode('utf-8')
                

Best Practices for Encryption

  • Use strong keys: Longer, random keys provide better security
  • Store keys securely: Never hardcode encryption keys in your application
  • Use modern algorithms: Prefer AES over older algorithms like DES or RC4
  • Implement proper key management: Consider using a key management system for production applications
  • Don't reinvent the wheel: Use established cryptographic libraries rather than implementing encryption yourself