Lädt...

🔧 Unlocking Easy Encryption with `easy-cipher-mate`: A Developer's Dream Come True


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

In a world where data breaches make headlines daily, securing sensitive information is no longer optional—it's a necessity. Yet, for many developers, encryption feels like a daunting maze. JavaScript encryption libraries often come with steep learning curves: picking the right algorithm, managing keys securely, handling initialization vectors, and avoiding rookie mistakes that could expose your data. And what about those times when you just need a quick, reliable way to encrypt a file without writing a single line of code? The command-line tools out there are either too complex or nonexistent for simple tasks.

Say goodbye to those headaches. Meet easy-cipher-mate, a game-changing library and CLI tool that brings encryption to your fingertips—whether you're coding in Node.js, working in the browser, or just need a fast terminal command. With robust algorithms like AES-GCM and ChaCha20-Poly1305, it simplifies secure text and file encryption while offering a seamless experience for both beginners and seasoned pros. Let’s dive into how this tool can transform your workflow, with real-world examples and a peek under the hood for the geeks among us.

What is easy-cipher-mate?

easy-cipher-mate is a versatile encryption powerhouse designed to make security accessible. Here’s what it offers:

  • Multiple Algorithms: Choose AES-GCM for trusted symmetric encryption or ChaCha20-Poly1305 for high-performance scenarios.
  • Text and File Encryption: Secure strings in your app or entire files on disk.
  • CLI Convenience: Encrypt and decrypt files directly from the command line—no coding required.
  • Multi-Language Support: Handle different text encodings for global applications.
  • Flexible Configuration: Set up encryption via code, environment variables, or JSON files.

Whether you're safeguarding user data in a web app or locking down sensitive config files, this tool has you covered.

Installing easy-cipher-mate

If you’re new to this, don’t worry—installation is a breeze. Open your terminal and run:

npm install easy-cipher-mate

Or, if you prefer Yarn:

yarn add easy-cipher-mate

That’s it! You’re ready to start securing your data.

Solving Real Problems with the CLI

Imagine you’re a system administrator tasked with securing a secrets.json file containing API keys. Writing a custom script feels like overkill, and you need it done now. With easy-cipher-mate’s CLI, it’s a one-liner.

Encrypting a File

Run this command:

easy-cipher-mate encrypt-file -i secrets.json -o secrets.json.encrypted -p "my-super-secret" -a aes-gcm
  • -i: Input file (secrets.json).
  • -o: Output file (secrets.json.encrypted).
  • -p: Your password.
  • -a: Algorithm (defaults to aes-gcm).

Boom! Your file is encrypted with AES-GCM, safe from prying eyes.

Decrypting a File

Later, when you need access:

easy-cipher-mate decrypt-file -i secrets.json.encrypted -o secrets.json.decrypted -p "my-super-secret" -a aes-gcm

The original file is back, decrypted and ready to use.

Encrypting Logs Line by Line

Now, suppose you’re a developer managing a log file (app.log) where each line is a sensitive event. Encrypting the whole file might not suit your needs—you want to secure each line individually for easier processing later. Here’s how:

easy-cipher-mate encrypt-text-file -f app.log -p "logpassword123" -a aes-gcm -e utf-8
  • -f: File to encrypt.
  • -e: Text encoding (e.g., utf-8 for standard text).

Each non-empty line is encrypted independently and saved in place as base64-encoded text. To decrypt:

easy-cipher-mate decrypt-text-file -f app.log -p "logpassword123" -a aes-gcm -e utf-8

Your logs are back to readable text, line by line. This is perfect for automated scripts or incremental log processing.

Powering Your Code with the API

For developers building applications, easy-cipher-mate shines with its intuitive API. Let’s explore some practical scenarios.

Securing User Input

You’re building a chat app, and you need to encrypt messages before storing them. Here’s how to encrypt a user’s message:

import { AESGCMEncryption, AESGCMEncryptionConfigFromEnv, EncryptionService } from 'easy-cipher-mate';

const algo = new AESGCMEncryption();
const config = new AESGCMEncryptionConfigFromEnv('chatsecret123');
const service = new EncryptionService(algo, config);

async function encryptMessage() {
  const message = "Hey, let's meet at 5 PM!";
  const encrypted = await service.encryptText(message);
  console.log('Encrypted:', encrypted.data);
  return encrypted.data;
}

To decrypt it later:

async function decryptMessage(encryptedData: ArrayBuffer) {
  const decrypted = await service.decryptText(encryptedData);
  console.log('Decrypted:', decrypted); // "Hey, let's meet at 5 PM!"
}

Simple, secure, and ready to integrate into your app.

Protecting a PDF Invoice

Say you’re generating invoices as PDFs and need to encrypt them before emailing. Here’s the code:

import { readFileSync, writeFileSync } from 'fs';
import { AESGCMEncryption, AESGCMEncryptionConfigFromEnv, EncryptionService } from 'easy-cipher-mate';

const algo = new AESGCMEncryption();
const config = new AESGCMEncryptionConfigFromEnv('invoicekey');
const service = new EncryptionService(algo, config);

async function encryptInvoice() {
  const fileBuffer = readFileSync('invoice.pdf');
  const arrayBuffer = fileBuffer.buffer.slice(fileBuffer.byteOffset, fileBuffer.byteOffset + fileBuffer.byteLength);

  const encrypted = await service.encryptFile(arrayBuffer);
  writeFileSync('invoice.pdf.encrypted', Buffer.from(encrypted.data));
}

To decrypt:

async function decryptInvoice() {
  const encryptedBuffer = readFileSync('invoice.pdf.encrypted');
  const encryptedArrayBuffer = encryptedBuffer.buffer.slice(
    encryptedBuffer.byteOffset,
    encryptedBuffer.byteOffset + encryptedBuffer.byteLength
  );

  const decrypted = await service.decryptFile(encryptedArrayBuffer);
  writeFileSync('invoice.pdf.decrypted', Buffer.from(decrypted));
}

Your invoices are now secure and easy to manage.

Supporting Global Users

If your app serves users worldwide, text encoding matters. Encrypting Japanese text, for example:

const japaneseMessage = 'こんにちは、世界!';
const encrypted = await service.encryptText(japaneseMessage, 'utf16le');
const decrypted = await service.decryptText(encrypted.data, 'utf16le');
console.log(decrypted); // 'こんにちは、世界!'

Supported encodings include utf-8, utf16le, base64, hex, latin1, and more—perfect for internationalization.

Configuration Made Easy

easy-cipher-mate offers flexible configuration options:

  • Environment Variables:
  export ECM_AESGCM_PASSWORD="mysecret"
  export ECM_AESGCM_SALT=$(echo -n "salt123" | base64)
  export ECM_AESGCM_IV=$(echo -n "iv456" | base64)

Then in code:

  const config = new AESGCMEncryptionConfigFromEnv();
  • JSON Config:
  {
    "password": "mysecret",
    "salt": "c2FsdDEyMw==", // base64 "salt123"
    "iv": "aXY0NTY=",      // base64 "iv456"
    "textEncoding": "utf-8"
  }

Load it with:

  const config = new AESGCMEncryptionConfigFromJSONFile('config.json');

Choose what fits your workflow—coding, scripting, or both.

For the Geeks: A Peek Under the Hood

Curious about how it works? Let’s look at the key derivation in AESGCMEncryption.ts. The library uses PBKDF2 to turn your password into a secure key:

async function deriveKey(password: string, salt: Uint8Array): Promise<CryptoKey> {
  const encoder = new TextEncoder();
  const keyMaterial = await crypto.subtle.importKey(
    "raw",
    encoder.encode(password),
    "PBKDF2",
    false,
    ["deriveKey"]
  );
  return crypto.subtle.deriveKey(
    {
      name: "PBKDF2",
      salt,
      iterations: 100000,
      hash: "SHA-256"
    },
    keyMaterial,
    { name: "AES-GCM", length: 256 },
    false,
    ["encrypt", "decrypt"]
  );
}

This process iterates 100,000 times with SHA-256 hashing, making brute-force attacks impractical. The Web Crypto API then handles the actual encryption, ensuring top-tier security standards. For files, the same key encrypts the entire buffer, while the CLI’s line-by-line mode applies this per line, encoding results in base64 for text compatibility.

Why You’ll Love easy-cipher-mate

From its dead-simple CLI to its developer-friendly API, easy-cipher-mate takes the pain out of encryption. It’s fast, secure, and flexible enough for any use case—whether you’re a novice securing your first file or a pro building a global app. Install it today with npm install easy-cipher-mate, and see how easy encryption can be.

Ready to lock down your data? Give easy-cipher-mate a spin and share your experience!

...

🔧 Say Goodbye to Redundancy with Spring2TS: A Developer’s Dream Come True


📈 36.3 Punkte
🔧 Programmierung

🐧 Padovan: A dream come true


📈 30.88 Punkte
🐧 Linux Tipps

🐧 Padovan: A dream come true


📈 30.88 Punkte
🐧 Linux Tipps

🐧 A dream come true: Android is finally using DRM/KMS


📈 30.88 Punkte
🐧 Linux Tipps

📰 The Microsoft Surface Phone Dream Could Still Come True, New Patent Suggests


📈 30.88 Punkte
📰 IT Security Nachrichten

🕵️ This new Linux handheld PC could be a tinkerer's dream come true


📈 30.88 Punkte
🕵️ Hacking

📰 I've tested hundreds of microphones, and this one is a podcaster's dream come true


📈 30.88 Punkte
📰 IT Nachrichten

📰 Trump’s “Deal of the Century” is Bibi’s Dream Come True


📈 30.88 Punkte
📰 IT Security Nachrichten

🪟 xCloud on iPad is my dream come true, but it's just a start


📈 30.88 Punkte
🪟 Windows Tipps

📰 Microsoft’s Azure Security Labs Is a Dream Come True for Hackers


📈 30.88 Punkte
📰 IT Security Nachrichten

📰 The Dream of a Real Windows 10 Phone Could Finally Come True


📈 30.88 Punkte
📰 IT Security Nachrichten

📰 Google’s Latest Smartwatch Deal Could Make the Pixel Watch a Dream Come True


📈 30.88 Punkte
📰 IT Security Nachrichten

📰 Google’s Latest Smartwatch Deal Could Make the Pixel Watch a Dream Come True


📈 30.88 Punkte
📰 IT Security Nachrichten

🪟 After Dream Tracks, YouTube now testing out Dream Screen, AI green screen backgrounds


📈 23.91 Punkte
🪟 Windows Tipps

📰 Huawei’s Dream Briefly Comes True, Crowned the World’s Largest Phone Maker


📈 21.74 Punkte
📰 IT Security Nachrichten

📰 One billion certificates later, Let's Encrypt's crazy dream to secure the web is coming true


📈 21.74 Punkte
📰 IT Security Nachrichten

📰 The Dream of Android Apps on Linux Phones Is So Close to Coming True


📈 21.74 Punkte
📰 IT Security Nachrichten

📰 Microsoft’s Foldable Dream Coming True: Dell Announces Concept Ori and Duet


📈 21.74 Punkte
📰 IT Security Nachrichten

📰 Apple’s Dream (And Ours) of an Unhackable iPhone Is Finally Coming True


📈 21.74 Punkte
📰 IT Security Nachrichten

📰 Microsoft’s Surface Phone Could Be a Dream Coming True If This Patent Is Used


📈 21.74 Punkte
📰 IT Security Nachrichten

🍏 Prime Video: Neue exklusive Sport-Doku „Bayer Leverkusen – A Dream Comes True“


📈 21.74 Punkte
🍏 iOS / Mac OS

📰 Adobe Photoshop Running on a Windows Phone Is a Dream Coming True Too Late


📈 21.74 Punkte
📰 IT Security Nachrichten

🔧 Unlocking Developer Experience: The Power of Doc-E - The Developer Engagement Platform


📈 20 Punkte
🔧 Programmierung

🔧 Mastering Literal Types in TypeScript: true as const vs true


📈 19.57 Punkte
🔧 Programmierung

🔧 CodeSOD: False True is True False


📈 19.57 Punkte
🔧 Programmierung

⚠️ Kaspersky &amp; Probrand Group: True partnership delivers True Cybersecurity


📈 19.57 Punkte
⚠️ Malware / Trojaner / Viren

📰 TaoTronics SoundLiberty 53 True Wireless Earbuds Review - True AirPods Pro Rival


📈 19.57 Punkte
📰 IT Security Nachrichten

📰 iOS 11 GM Leak verrät iPhone 8 Features: True Tone Display, True Tone Display ...


📈 19.57 Punkte
📰 IT Nachrichten

🔧 Unlocking the Power of spellcheck="true" in HTML: A Deep Dive for Developers


📈 18.96 Punkte
🔧 Programmierung

🔧 Unlocking Data's True Potential: Denoising as a Powerful Building Block


📈 18.96 Punkte
🔧 Programmierung

🎥 Are Managers the Key to Unlocking AI’s True Potential?


📈 18.96 Punkte
🎥 Video | Youtube

📰 Porn parking, livid lockers and botched blenders: The nightmare IoT world come true


📈 18.93 Punkte
📰 IT Security Nachrichten

matomo