Files
2026-10-25 11:25:55 -04:00

508 lines
24 KiB
HTML

<!DOCTYPE html>
<html lang="en" data-bs-theme="auto">
<!-- Mirrored from https://imagemagick.org/cipher/ by HTTrack Website Copier/3.x [XR&CO], Sun, 25 Oct 2026 15:23:43 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>ImageMagick | Encipher or Decipher an Image</title>
<meta name="description" content="Learn how ImageMagick applies cipher functions to encrypt and decrypt image pixels. Explore supported algorithms, usage examples, and how ciphers enhance image security and controlled access.">
<link rel="canonical" href="index.html">
<meta name="robots" content="index, follow">
<meta name="theme-color" content="#0d1117">
<link rel="shortcut icon" href="../image/wand.png" type="image/png">
<link rel="apple-touch-icon" href="../image/wand.png" type="image/png">
<!-- Fonts & Icons -->
<link rel="preconnect" href="https://fonts.googleapis.com/">
<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600&amp;family=Inter:wght@300;400;500;600;700&amp;display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css">
<style>
:root {
--im-font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
--im-font-mono: 'Fira Code', monospace;
--im-primary: #8b5cf6;
--im-primary-hover: #7c3aed;
--im-accent: #f59e0b;
--im-bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
}
body {
font-family: var(--im-font-sans);
min-height: 100vh;
display: flex;
flex-direction: column;
}
code, kbd, pre, .font-mono {
font-family: var(--im-font-mono) !important;
}
/* Modern Navbar */
.im-navbar {
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
background-color: rgba(15, 23, 42, 0.85) !important;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.im-navbar .nav-link {
font-weight: 500;
color: rgba(255, 255, 255, 0.75);
transition: all 0.2s ease;
padding: 0.5rem 0.85rem;
border-radius: 0.375rem;
}
.im-navbar .nav-link:hover,
.im-navbar .nav-link.active {
color: #ffffff !important;
background: rgba(255, 255, 255, 0.08);
}
.im-brand {
font-weight: 700;
letter-spacing: -0.02em;
background: linear-gradient(135deg, #a78bfa 0%, #f472b6 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
display: flex;
align-items: center;
gap: 0.5rem;
}
/* Hero Section */
.im-hero {
background: var(--im-bg-gradient);
color: #ffffff;
padding: 4rem 0 3.5rem;
position: relative;
overflow: hidden;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.im-hero::before {
content: '';
position: absolute;
top: -50%;
right: -10%;
width: 500px;
height: 500px;
background: radial-gradient(circle, rgba(139, 92, 246, 0.15) 0%, rgba(0,0,0,0) 70%);
pointer-events: none;
}
/* Terminal Widget */
.terminal-card {
background: #090d16;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 0.75rem;
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
overflow: hidden;
}
.terminal-header {
background: rgba(255, 255, 255, 0.04);
padding: 0.6rem 1rem;
display: flex;
align-items: center;
gap: 0.5rem;
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.terminal-dot {
width: 10px;
height: 10px;
border-radius: 50%;
}
/* Cards & Container */
.im-card {
border: 1px solid var(--bs-border-color-translucent);
border-radius: 0.75rem;
transition: transform 0.2s ease, box-shadow 0.2s ease;
background: var(--bs-body-bg);
}
.im-card:hover {
transform: translateY(-2px);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.08);
}
/* Footer */
.im-footer {
margin-top: auto;
background: #090d16;
color: rgba(255, 255, 255, 0.6);
border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.im-footer a {
color: rgba(255, 255, 255, 0.75);
text-decoration: none;
transition: color 0.2s;
}
.im-footer a:hover {
color: var(--im-primary);
}
</style>
<!-- Open Graph -->
<meta property="og:title" content="ImageMagick | Encipher or Decipher an Image">
<meta property="og:description" content="Learn how ImageMagick applies cipher functions to encrypt and decrypt image pixels. Explore supported algorithms, usage examples, and how ciphers enhance image security and controlled access.">
<meta property="og:image" content="../image/logo.png">
<meta property="og:url" content="index.html">
<meta property="og:type" content="website">
<!-- JSON-LD Structured Data -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "SoftwareApplication",
"name": "ImageMagick",
"url": "https://imagemagick.org/cipher/",
"image": "https://imagemagick.org/image/logo.png",
"description": "Learn how ImageMagick applies cipher functions to encrypt and decrypt image pixels. Explore supported algorithms, usage examples, and how ciphers enhance image security and controlled access.",
"applicationCategory": "MultimediaApplication",
"operatingSystem": "Windows, macOS, Linux, Unix",
"softwareVersion": "7.1.2-34",
"license": "https://imagemagick.org/license/",
"offers": {
"@type": "Offer",
"price": "0.00",
"priceCurrency": "USD"
}
}
</script>
<script async src="https://cse.google.com/cse.js?cx=8720b81722164487b"></script>
</head>
<body>
<!-- Theme Init -->
<script>
(function() {
const saved = localStorage.getItem('theme') || 'auto';
const systemDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const applied = saved === 'auto' ? (systemDark ? 'dark' : 'light') : saved;
document.documentElement.setAttribute('data-bs-theme', applied);
})();
</script>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark fixed-top im-navbar">
<div class="container-xl">
<a class="navbar-brand im-brand" href="../index-2.html">
<img src="../image/wand.png" alt="Wand Icon" width="24" height="24" class="d-inline-block align-text-top">
ImageMagick
</a>
<button class="navbar-toggler border-0" type="button" data-bs-toggle="collapse" data-bs-target="#imNavbar" aria-controls="imNavbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="imNavbar">
<ul class="navbar-nav me-auto mb-2 mb-lg-0 ms-lg-3">
<li class="nav-item">
<a class="nav-link " href="../download/index.html">Download</a>
</li>
<li class="nav-item">
<a class="nav-link " href="../command-line-tools/index.html">Tools</a>
</li>
<li class="nav-item">
<a class="nav-link " href="../command-line-processing/index.html">CLI Usage</a>
</li>
<li class="nav-item">
<a class="nav-link " href="../develop/index.html">API & Develop</a>
</li>
<li class="nav-item">
<a class="nav-link" rel="noopener noreferrer" target="_blank" href="https://github.com/ImageMagick/ImageMagick/discussions">Community</a>
</li>
</ul>
<div class="d-flex align-items-center gap-2">
<!-- Search Trigger Modal / Input -->
<form class="d-flex" action="https://imagemagick.org/cipher/index.html" role="search">
<div class="input-group input-group-sm">
<input class="form-control bg-body-tertiary border-secondary-subtle" type="search" placeholder="Search site..." name="q" aria-label="Search">
<button class="btn btn-outline-warning" type="submit" name="sa"><i class="bi bi-search"></i></button>
</div>
</form>
<!-- Theme Dropdown -->
<div class="dropdown">
<button class="btn btn-sm btn-outline-secondary dropdown-toggle d-flex align-items-center gap-1 border-0 text-white" type="button" id="themeSelect" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-circle-half"></i>
</button>
<ul class="dropdown-menu dropdown-menu-end shadow" aria-labelledby="themeSelect">
<li><button class="dropdown-item d-flex align-items-center gap-2" onclick="setTheme('light')"><i class="bi bi-sun-fill"></i> Light</button></li>
<li><button class="dropdown-item d-flex align-items-center gap-2" onclick="setTheme('dark')"><i class="bi bi-moon-stars-fill"></i> Dark</button></li>
<li><button class="dropdown-item d-flex align-items-center gap-2" onclick="setTheme('auto')"><i class="bi bi-circle-half"></i> Auto</button></li>
</ul>
</div>
<a href="https://github.com/ImageMagick/ImageMagick" target="_blank" class="btn btn-sm btn-outline-light d-flex align-items-center gap-1 ms-1">
<i class="bi bi-github"></i> <span class="d-none d-xl-inline">GitHub</span>
</a>
</div>
</div>
</div>
</nav>
<!-- Hero Header Block -->
<header class="im-hero mt-5 pt-5">
<div class="container-xl pt-3">
<div class="row align-items-center g-4">
<div class="col-lg-7">
<div class="d-inline-flex align-items-center gap-2 px-3 py-1 rounded-pill bg-primary bg-opacity-20 text-primary border border-primary border-opacity-30 mb-3 fs-7">
<span class="badge bg-primary">v7.1.2-34</span>
<span class="small text-light">Latest Stable Release</span>
</div>
<h1 class="display-4 fw-bold mb-3 tracking-tight">Encipher or Decipher an Image</h1>
<p class="lead text-light opacity-75 mb-4 fs-5">Learn how ImageMagick applies cipher functions to encrypt and decrypt image pixels. Explore supported algorithms, usage examples, and how ciphers enhance image security and controlled access.</p>
<div class="d-flex flex-wrap gap-3">
<a href="../download/index.html" class="btn btn-primary btn-lg px-4 fw-semibold d-flex align-items-center gap-2 shadow">
<i class="bi bi-download"></i> Get ImageMagick
</a>
<a href="../command-line-processing/index.html" class="btn btn-outline-light btn-lg px-4 fw-semibold d-flex align-items-center gap-2">
<i class="bi bi-terminal"></i> Documentation
</a>
</div>
</div>
<!-- Terminal Quickstart Preview -->
<div class="col-lg-5">
<div class="terminal-card">
<div class="terminal-header">
<div class="terminal-dot bg-danger"></div>
<div class="terminal-dot bg-warning"></div>
<div class="terminal-dot bg-success"></div>
<span class="small text-secondary font-mono ms-2">quickstart.sh</span>
</div>
<div class="p-3 text-light font-mono small">
<div class="text-secondary"># Install via your favorite Package Manager</div>
<div class="text-success">$ brew install imagemagick</div>
<div class="text-secondary mt-2"># Convert PNG to WebP with compression</div>
<div>$ magick input.png -quality 85 output.webp</div>
<div class="text-secondary mt-2"># Resize image maintaining aspect ratio</div>
<div>$ magick input.jpg -resize 800x600^ output.jpg</div>
</div>
</div>
</div>
</div>
</div>
</header>
<!-- Main Body Content -->
<main class="py-5">
<div class="container-xl">
<div class="row g-5">
<!-- Main Column -->
<div class="col-lg-8">
<div class="container-fluid px-0">
<!-- Quick Navigation & Lead Introduction -->
<div class="row mb-4">
<div class="col-12">
<div class="d-flex flex-wrap gap-2 pt-2 pb-3 border-bottom mb-3">
<a href="#encipher" class="btn btn-outline-secondary btn-sm">Encipher an Image</a>
<a href="#decipher" class="btn btn-outline-secondary btn-sm">Decipher an Image</a>
<a href="#caveats" class="btn btn-outline-secondary btn-sm">Encipher and Decipher Caveats</a>
</div>
<p class="lead text-body-secondary">
Most images, by design, are made to be viewed often and by many people. Web images, for example, may be viewed hundreds of times a day by a multitude of visitors. However, in some cases, you may want to keep a particular image private so that only you or a select group of friends or web visitors can view it. ImageMagick permits you to scramble your images such that unless someone knows your passphrase, they will be unable to view the original content.
</p>
<p class="text-muted small">
You could use an <a href="https://github.com/ImageMagick/WizardsToolkit">enciphering</a> utility to scramble your image, but they typically scramble the entire file making it unrecognizable as an image format. With ImageMagick, only the pixels are scrambled. The scrambled image continues to be recognized as an image and will even display in your web page, though the content appears as gibberish rather than the original image.
</p>
</div>
</div>
<!-- Encipher an Image Section -->
<section id="encipher" class="mb-5">
<h2 class="h4 pb-2 border-bottom mb-3">Encipher an Image</h2>
<p>
Use the <a href="../command-line-options/index.html#encipher">-encipher</a> option to scramble your image so that it is unrecognizable. This option requires a filename containing your passphrase. In this example, we scramble an image and save it in the PNG format:
</p>
<div class="card bg-body-tertiary border-0 shadow-sm mb-3">
<div class="card-body">
<pre class="mb-0 font-monospace text-body-secondary"><samp>$ magick rose.jpg -encipher passphrase.txt rose.png</samp></pre>
</div>
</div>
<p class="mt-3">Here is an example where we encipher an image using another image as the passphrase:</p>
<div class="card bg-body-tertiary border-0 shadow-sm mb-3">
<div class="card-body">
<pre class="mb-0 font-monospace text-body-secondary"><samp>$ magick rose.jpg -encipher smiley.gif rose.png</samp></pre>
</div>
</div>
</section>
<!-- Decipher an Image Section -->
<section id="decipher" class="mb-5">
<h2 class="h4 pb-2 border-bottom mb-3">Decipher an Image</h2>
<p>
Use the <a href="../command-line-options/index.html#decipher">-decipher</a> option to unscramble your image so that it is recognizable once again. This option also requires a filename containing your passphrase. In this example, we unscramble an image and save it in the JPEG format:
</p>
<div class="card bg-body-tertiary border-0 shadow-sm mb-3">
<div class="card-body">
<pre class="mb-0 font-monospace text-body-secondary"><samp>$ magick rose.png -decipher passphrase.txt rose.jpg</samp></pre>
</div>
</div>
</section>
<!-- Caveats Section -->
<section id="caveats" class="mb-4">
<h2 class="h4 pb-2 border-bottom mb-3">Encipher and Decipher Caveats</h2>
<div class="row g-4 mb-4">
<div class="col-md-6">
<div class="card h-100 border-0 bg-body-tertiary shadow-sm">
<div class="card-body">
<h3 class="h6 fw-bold mb-2">Format &amp; Pixel Support</h3>
<p class="small text-muted mb-0">
Some formats (such as JPEG or GIF) do not support enciphered pixels. To ensure your format is supported, encipher a test image and verify you can restore its original content <var>before</var> processing additional images. Furthermore, because formats may only support 8-bit and RGB (TrueColor), you may want to include options like <code>-depth 8 -type TrueColor</code> before your output filename.
</p>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card h-100 border-0 bg-body-tertiary shadow-sm">
<div class="card-body">
<h3 class="h6 fw-bold mb-2">Passphrase Security</h3>
<p class="small text-muted mb-0">
Passphrases can combine letters and symbols and should be a minimum of 12 characters to help ensure privacy. Ensure your passphrase file permissions prevent unauthorized reading. Additionally, if you lose or forget your passphrase, your original image content is lost forever. Note that ImageMagick only scrambles image pixels; metadata remains untouched and readable.
</p>
</div>
</div>
</div>
</div>
<h3 class="h5 mt-4 mb-3">Cryptographic Details &amp; Limitations</h3>
<p>
ImageMagick uses AES in Counter (CTR) mode to scramble an image's pixel data. The current implementation derives both the AES key and the initial counter (IV) deterministically from the user-supplied passphrase: the first half becomes the AES key, while the second half is hashed alongside image dimensions to produce the IV. Because this IV relies solely on the passphrase and dimensions, encrypting multiple images with the same passphrase and dimensions produces identical IVs and keystreams.
</p>
<p>
CTR mode requires a unique, non-repeating IV for every encryption under the same key. Reusing an IV causes keystream reuse, allowing attackers to recover information about plaintexts by XORing ciphertexts. Because of this deterministic IV construction, ImageMagick's encipher feature is suitable only for casual obfuscation rather than security-sensitive encryption. Avoiding keystream reuse would require supplying a unique passphrase per image, which is impractical and falls short of modern cryptographic expectations.
</p>
<div class="card border-0 bg-body-tertiary shadow-sm mt-3 mb-3">
<div class="card-body">
<h4 class="h6 fw-bold mb-2">Interoperability and Examples</h4>
<p class="small text-muted mb-0">
Currently, only ImageMagick can restore enciphered image content, though standard ciphers and modes are used so other vendors could theoretically support it. Small practical examples of image enciphering can be found in the IM Examples under <a href="https://usage.imagemagick.org/transform/#encipher">Encrypting Image Data</a>.
</p>
</div>
</div>
</section>
</div>
</div>
<!-- Right Sidebar -->
<aside class="col-lg-4">
<div class="sticky-top" style="top: 90px;">
<!-- Sponsor Card -->
<div class="card im-card mb-4 overflow-hidden border-0 bg-gradient bg-primary bg-opacity-10">
<div class="card-body p-4 text-center">
<img src="../image/wizard.jpg" alt="ImageMagick Wizard" class="rounded shadow mb-3 img-fluid" style="max-height: 200px;">
<h5 class="fw-bold">Support Open Source</h5>
<p class="small text-body-secondary mb-3">Help maintain and sustain ImageMagick development.</p>
<iframe src="https://github.com/sponsors/ImageMagick/button" title="Sponsor ImageMagick" height="35" width="114" class="border-0"></iframe>
</div>
</div>
<!-- Banner Ad Container -->
<div class="text-center p-2 mv-4 rounded border border-secondary-subtle bg-body-tertiary">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3129977114552745" crossorigin="anonymous"></script>
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-3129977114552745"
data-ad-slot="1083537442"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<!-- Quick Links Navigation -->
<div class="card im-card p-3 mb-4">
<h6 class="fw-bold text-uppercase fs-7 text-secondary mb-3">Resources</h6>
<ul class="nav flex-column gap-1 fs-6">
<li class="nav-item"><a href="../security-policy/index.html" class="nav-link p-2 rounded text-body-secondary"><i class="bi bi-shield-check me-2 text-success"></i> Security Policy</a></li>
<li class="nav-item"><a href="../license/index.html" class="nav-link p-2 rounded text-body-secondary"><i class="bi bi-file-earmark-text me-2 text-info"></i> Open Source License</a></li>
<li class="nav-item"><a href="../porting/index.html" class="nav-link p-2 rounded text-body-secondary"><i class="bi bi-signpost-split me-2 text-warning"></i> Porting v6 to v7</a></li>
<li class="nav-item"><a href="../formats/index.html" class="nav-link p-2 rounded text-body-secondary"><i class="bi bi-filetype-png me-2 text-danger"></i> Supported Formats</a></li>
</ul>
</div>
</div>
</aside>
</div>
</div>
</main>
<!-- Footer -->
<footer class="im-footer py-5 mt-auto">
<div class="container-xl">
<div class="row g-4">
<div class="col-md-6 col-lg-4">
<a class="navbar-brand im-brand mb-2 fs-5" href="../index-2.html">ImageMagick</a>
<p class="small text-secondary">Mastering Digital Image Alchemy. The open-source suite for image creation, conversion, and batch manipulation.</p>
</div>
<div class="col-6 col-md-3 col-lg-2">
<h6 class="text-light fw-bold mb-3">Navigation</h6>
<ul class="list-unstyled small d-flex flex-column gap-2">
<li><a href="../download/index.html">Download</a></li>
<li><a href="../command-line-tools/index.html">Tools</a></li>
<li><a href="../develop/index.html">APIs & Libraries</a></li>
<li><a href="../sitemap/index.html">Sitemap</a></li>
</ul>
</div>
<div class="col-6 col-md-3 col-lg-2">
<h6 class="text-light fw-bold mb-3">Community</h6>
<ul class="list-unstyled small d-flex flex-column gap-2">
<li><a href="https://github.com/ImageMagick/ImageMagick/discussions" target="_blank">Discussions</a></li>
<li><a href="https://github.com/ImageMagick/ImageMagick/issues" target="_blank">Report an Issue</a></li>
<li><a href="../support/index.html">Sponsor Us</a></li>
<li><a href="../cite/index.html">Cite ImageMagick</a></li>
</ul>
</div>
<div class="col-md-6 col-lg-4">
<h6 class="text-light fw-bold mb-3">Connect</h6>
<div class="d-flex gap-3 fs-5">
<a href="https://github.com/imagemagick/imagemagick" target="_blank" aria-label="GitHub"><i class="bi bi-github"></i></a>
<a href="https://x.com/imagemagick" target="_blank" aria-label="X/Twitter"><i class="bi bi-twitter-x"></i></a>
</div>
<p class="small text-secondary mt-3 mb-0">Copyright © 1999 ImageMagick Studio LLC</p>
</div>
</div>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js"></script>
<script>
function setTheme(theme) {
localStorage.setItem('theme', theme);
const systemDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const applied = theme === 'auto' ? (systemDark ? 'dark' : 'light') : theme;
document.documentElement.setAttribute('data-bs-theme', applied);
}
</script>
<div style="visibility: hidden;">
<div class="gcse-search"></div>
</div>
</body>
<!-- Mirrored from https://imagemagick.org/cipher/ by HTTrack Website Copier/3.x [XR&CO], Sun, 25 Oct 2026 15:23:43 GMT -->
</html>