des-ecb encrypt & decrypt online

Legacy

Encrypt or decrypt text with des-ecb and a secret. Same result as PHP's openssl_encrypt, and nothing leaves your browser.

Padded with zero bytes or cut to 8 bytes.
Runs in your browser
What the tool did

The bytes behind your result

Your code gives a different result? Almost always the key or the IV differ. Here you see exactly which bytes the tool used for the secret and text in the tool above: copy the key and IV in hex into your own code. Shown for the text hello world and the secret my secret until you type above.

Key · 8 bytes 8 from your secret, 1 cut off
6d79207365637265
6d79207365637265
IV
not used by this mode
Text in UTF-8 11 bytes of text + 5 bytes PKCS#7 padding (value 05) = 16 bytes, 2 blocks of 8
68656c6c6f20776f
726c640505050505
Encrypted · 16 bytes
44d594dd79de287e
e6254e1f22d73c4c
44d594dd79de287ee6254e1f22d73c4c
As Base64 what the tool shows
RNWU3XneKH7mJU4fItc8TA==
  • Your secret is longer than the key. The bytes after the key length are ignored.
  • DES ignores the lowest bit of each key byte (parity bit).

from your inputzero bytespaddingciphertext

In short

What is des-ecb?

DES is the US standard cipher from 1977. Its 56-bit key is far too short: in 1999 a public effort found a DES key in 22 hours. It is only used to read or match old data. DES-ECB uses a 64-bit key (16 rounds) in Electronic Codebook mode: every block is encrypted on its own, so equal blocks give equal output.

BrokenDES: Can be attacked in practice. Only use it to read or match old data.

How your secret becomes the key

DES-ECB needs exactly 8 bytes (64 bits) of key. The tool takes your secret as UTF-8 bytes and pads it with zero bytes to 8 bytes, or cuts it after 8 bytes. DES only uses 7 bits of each key byte: the lowest bit is a parity bit and ignored, so 56 bits count.

Where you meet DES
  • Old banking and payment systems
  • Legacy file formats and protocols
  • Teaching (Feistel networks)
Honest answer

Is it safe to use?

The cipher: broken

DES. Can be attacked in practice. Only use it to read or match old data.

This setup: for compatibility

The setup of this tool is made for compatibility with PHP's openssl_encrypt, not for protecting secrets: the IV is always zero, the secret is used as the key without a key derivation function, and nothing detects changes to the ciphertext.

For real secrets use an authenticated mode such as AES-256-GCM or ChaCha20-Poly1305 with a fresh random nonce for every message, and derive the key from a password with Argon2id, scrypt or PBKDF2. What is a key derivation function?

Electronic Codebook

How ECB mode works

ECB encrypts each 8-byte block separately with the same key. There is no IV and no chaining.

Equal plaintext blocks therefore give equal ciphertext blocks. Patterns in the data stay visible, the classic example is an encrypted image whose outlines you can still see. Never use ECB for more than one block of real data.

Like CBC, ECB pads the last block with PKCS#7, so the output is a multiple of 8 bytes.

Original: 144 blocks of 8 bytes
des-ecb
des-cbc

Really calculated: each square is one 8-byte block, coloured by the first byte of its ciphertext. With ECB, equal blocks stay equal and the heart shows through. With CBC, every block depends on the one before.

Use it in code

The same result in your code

Every snippet prints RNWU3XneKH7mJU4fItc8TA== for the text hello world and the secret my secret, the same as the tool. The key and IV are written out in hex, so you can see what the tool does with the secret. Your own key and IV are in What the tool did. All snippets are run against PHP before each release.

PHP
$key = hex2bin("6d79207365637265"); // "my secret" cut to 8 bytes
echo openssl_encrypt("hello world", "des-ecb", $key, 0);

Shortest form, same result: openssl_encrypt("hello world", "des-ecb", "my secret"). PHP pads the secret itself but warns about the empty IV. On OpenSSL 3, PHP needs the legacy provider enabled in openssl.cnf.

Python
# pip install cryptography
import base64
from cryptography.hazmat.primitives.ciphers import Cipher, modes
from cryptography.hazmat.decrepit.ciphers import algorithms
from cryptography.hazmat.primitives import padding

key = bytes.fromhex("6d79207365637265")  # "my secret" cut to 8 bytes
data = "hello world".encode()
padder = padding.PKCS7(64).padder()
data = padder.update(data) + padder.finalize()
enc = Cipher(algorithms.TripleDES(key), modes.ECB()).encryptor()
print(base64.b64encode(enc.update(data) + enc.finalize()).decode())

Python has no DES in the standard library; the cryptography package keeps it in its "decrepit" module for old data.

Node.js
import { createCipheriv } from 'node:crypto';

const key = Buffer.from("6d79207365637265", 'hex'); // "my secret" cut to 8 bytes
const c = createCipheriv("des-ecb", key, null);
console.log(Buffer.concat([c.update("hello world", 'utf8'), c.final()]).toString('base64'));

Run with node --openssl-legacy-provider: OpenSSL 3 hides this cipher by default.

Java
import javax.crypto.Cipher;
import javax.crypto.spec.*;
import java.util.Base64;
import java.util.HexFormat;

public class Encrypt {
  public static void main(String[] args) throws Exception {
    byte[] key = HexFormat.of().parseHex("6d79207365637265"); // "my secret" cut to 8 bytes
    Cipher c = Cipher.getInstance("DES/ECB/PKCS5Padding");
    c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "DES"));
    System.out.println(Base64.getEncoder().encodeToString(c.doFinal("hello world".getBytes("UTF-8"))));
  }
}

Java 17 or newer (HexFormat). Java's PKCS5Padding is the same as PKCS#7.

Go
package main

import (
	"bytes"
	"crypto/des"
	"encoding/base64"
	"encoding/hex"
	"fmt"
)

func main() {
	key, _ := hex.DecodeString("6d79207365637265") // "my secret" cut to 8 bytes
	block, _ := des.NewCipher(key)
	data := []byte("hello world")
	n := block.BlockSize() - len(data)%block.BlockSize() // PKCS#7 padding
	data = append(data, bytes.Repeat([]byte{byte(n)}, n)...)
	out := make([]byte, len(data))
	for i := 0; i < len(data); i += block.BlockSize() { // Go has no ECB mode: one block at a time
		block.Encrypt(out[i:], data[i:])
	}
	fmt.Println(base64.StdEncoding.EncodeToString(out))
}
Command line
printf '%s' 'hello world' | openssl enc -des-ecb -K 6d79207365637265 -provider legacy -provider default -a -A

printf instead of echo: echo adds a line break, which changes the result. -K and -iv take hex; with -k or -pass, openssl derives a different key from a password.

Common mistakes

Why your des-ecb result doesn't match

You hashed the secret first

Many tutorials turn a password into a key with SHA-256 or MD5. This tool doesn't: it uses the bytes of your secret directly and pads them with zero bytes. Copy the key in hex from What the tool did and use it as the raw key.

Hex instead of Base64

The tool shows the raw ciphertext bytes as Base64. Many libraries return hex or raw bytes. Convert before comparing, or compare with the hex blocks in What the tool did.

Zero padding instead of PKCS#7

The tool pads with PKCS#7 (OpenSSL's default). Some libraries pad with zeros or not at all. A text of exactly one block still gets a full block of padding (10 10 … 10 for 16-byte blocks).

Same result as ECB for short texts

With a zero IV, the first CBC block is exactly the ECB block, because XOR with zeros changes nothing. Texts up to one block long (15 bytes plus padding) give the same result in CBC and ECB. From the second block on they differ, see the family comparison.

Two secrets, same result

DES ignores the lowest bit of every key byte. Secrets that differ only there, such as a and ` (0x61 and 0x60), give identical results.

Spaces and line breaks

Like the old site, the tool trims spaces and line breaks at the start and end of the text and the secret, and sends line breaks as CRLF (\r\n), as a browser form does. echo "text" | in a shell adds a line break at the end.

Your secret is longer than the key

Only the first bytes up to the key length count, the rest is cut off. Two secrets that start with the same bytes give the same result. Non-ASCII characters take 2–4 bytes in UTF-8, so they fill the key faster.

"unsupported" in OpenSSL 3

OpenSSL 3 moved this cipher to the legacy provider. Node.js, PHP, Python and the openssl command line built on OpenSSL 3 report it as unsupported until the legacy provider is loaded (node --openssl-legacy-provider, openssl enc -provider legacy -provider default).

openssl enc with -k or -pass

Given a password, the openssl command line derives key and IV from it with a random salt (EVP_BytesToKey or PBKDF2), and the output starts with U2FsdGVkX1 ("Salted__"). That is a different format. Pass the key and IV in hex with -K and -iv instead, as in the code example.

Which cipher was it?

Encrypted something here years ago?

Paste the Base64 result and the secret. Your browser tries all 174 ciphers of this site and shows those that give readable text. Useful if you don't remember the cipher, or to check whether your ciphertext really is des-ecb.

Nothing is sent anywhere. Wrong secrets give no readable text.
Compare

Every DES and Triple DES variant, same input

The text The quick brown fox jumps over the lazy dog (43 bytes) with the secret my secret in all 24 DES and Triple DES ciphers. The last column lists names that give the same result: aliases, and modes that agree for this input. Highlighted: the same start as des-ecb. Watch how CBC and ECB share the first block, and CFB, OFB and CTR the first 8 bytes. Type a text and a secret in the tool above to use yours.

CipherResult (Base64)Same as
des Legacy0bA3hT4PqaA6P4grYRvzUBUAGvpdcwiTCXJTZlMO1+yv2OEYGhgYmE4+DlE3oGJLdes-cbc
des-cbc Legacy0bA3hT4PqaA6P4grYRvzUBUAGvpdcwiTCXJTZlMO1+yv2OEYGhgYmE4+DlE3oGJLdes
des-cfb Legacy02Hv2U2qFHmk1YsGGuzyjbaEGYxerKIHMbyX+fDkXEjt3j/QeCcjB2AFzQ==
des-cfb1 Legacyxji1RZATdSX7BBIU+v0mKIdnN4gC0wIQlbrjgnbVDSlQTpWy+HM/U/Af7w==
des-cfb8 Legacy0zQRFiLI4IpoX3zhdxKoP1eOiGFjXyMl8M7XrqDRNqK5cDv9nyiZj08bsg==
des-ecb Legacy0bA3hT4PqaBGCTN+NK8kz6arEwlsenPMuftXeVy706LosWwgGNS/kAV39nzVgegs
des-ede LegacyVQAgAnCgtiTPsdxTJ6HFdLP0N7BqwPngn6rvJ26LipRlVJEqW+BoMeqmW6buZpdmdes-ede-ecb
des-ede-cbc LegacyVQAgAnCgtiQzlY21xKZdjPmLpLIRLR+NBtr8noYcRo4YHOZ3JvH+qsX5linqoR6M
des-ede-cfb LegacyarrxSsoIGF9JBiphmNZbdpVkVcXVmRlYKVHUIEF3A4KNYcxtupVf8IxAJw==
des-ede-ecb LegacyVQAgAnCgtiTPsdxTJ6HFdLP0N7BqwPngn6rvJ26LipRlVJEqW+BoMeqmW6buZpdmdes-ede
des-ede-ofb LegacyarrxSsoIGF9G9FnyO+6bgMQ9K0BQfn+xQ7bkCGh9igmU4kb3GHGDLTting==
des-ede3 LegacyWmVOV7KruhMo6OpASvcZz/SJTz4kbwgMaqYmUiKaPjOiOfE8YxysuP5gu0PUGvCYdes-ede3-ecb
des-ede3-cbc LegacyWmVOV7KruhOCm6HCT/9l8EejwpsvM/D2BjGsQB53EUCdyIiabE03/wGUkzjbJBPRdes3
des-ede3-cfb LegacyGyevnv0MdXSu2Z7GMEliPovFDV3FR3wbdd16B20q8AiP2jDwxtZL7dbgTw==
des-ede3-cfb1 LegacyV0b4gFcFbO+mMnZLTEwYAicPGcFdW8l16fjwjKiGmFFXoLpdlXOUJzkHaw==
des-ede3-cfb8 LegacyG/GpkCVSSBHihawied5fcV1jW05WwgtRZ1xaA0Env5OeC24hAkhCsjT+pQ==
des-ede3-ecb LegacyWmVOV7KruhMo6OpASvcZz/SJTz4kbwgMaqYmUiKaPjOiOfE8YxysuP5gu0PUGvCYdes-ede3
des-ede3-ofb LegacyGyevnv0MdXSuY5+gbTgo54KoOmCaKYqiytdUNhx+FLtZGzTdD66v15Qihg==
des-ofb Legacy02Hv2U2qFHmJWYhQyinFdiE6oI9dZjxmC3CZiJqx/NaMtHHrGCSl+WPg2A==
des3 LegacyWmVOV7KruhOCm6HCT/9l8EejwpsvM/D2BjGsQB53EUCdyIiabE03/wGUkzjbJBPRdes-ede3-cbc
des3-wrap Legacydifferent every time (random IV)
desx LegacynskG7SWseL+R4S+F5ZfWi36BUvVqJn4qFQpzjlrXkQ+e4WMfUL2tvxntpHuJ7Uu/desx-cbc
desx-cbc LegacynskG7SWseL+R4S+F5ZfWi36BUvVqJn4qFQpzjlrXkQ+e4WMfUL2tvxntpHuJ7Uu/desx
id-smime-alg-cms3deswrap Legacydifferent every time (random IV)
Test values

des-ecb test values

Results for common test strings with the secret my secret (UTF-8, no line break, zero IV), exactly as the tool and PHP's openssl_encrypt give them. Use them to check your own implementation.

Textdes-ecb (Base64)
empty stringceStRD+TJFQ=
aW9LcfihI8Zs=
hello worldRNWU3XneKH7mJU4fItc8TA==
0123456789abcdefhO4DHULBzwb9lQDCokkDhnHkrUQ/kyRU
The quick brown fox jumps over the lazy dog0bA3hT4PqaBGCTN+NK8kz6arEwlsenPMuftXeVy706LosWwgGNS/kAV39nzVgegs
FAQ

Questions about des-ecb

Can des-ecb be decrypted without the secret?

No. Without the secret there is no shortcut, except that DES's weak key lets a determined attacker try every key. A short or common secret can be guessed, though, because the tool uses it directly as the key.

Why does my des-ecb code give a different result?

Almost always because of the key or the IV: the tool pads your secret with zero bytes instead of hashing it and uses a zero IV. Also check Base64 vs hex, padding, and spaces or line breaks the tool trims.

Is des-ecb safe to use?

Not for real data. ECB encrypts equal blocks to equal output, so patterns in the data stay visible. Use it only to match an existing system.

Is DES secure?

No. DES can be attacked in practice. Use it only to read or match old data.

How long should my secret be?

Exactly 8 bytes (64 bits) fills the key; anything after that is ignored. For real security a random key is better than a typed word.

Good to know

Before you rely on it

Searches the list of pages on this site. What you type stays in your browser.