cast encrypt & decrypt online

Legacy

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

Shorter secrets are padded with zero bytes to 16 bytes. No IV, PHP uses zero 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 · 16 bytes 9 from your secret, 7 zero bytes added
6d792073656372657400000000000000
6d792073656372657400000000000000
IV · 8 bytes none given, so zero bytes
0000000000000000
0000000000000000
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
9e77badfef54de37
91736609f55a4165
9e77badfef54de3791736609f55a4165
As Base64 what the tool shows
nne63+9U3jeRc2YJ9VpBZQ==

from your inputzero bytespaddingciphertext

In short

What is cast?

cast is another name for cast5-cbc in OpenSSL and PHP: same key, same mode, same result. CAST5, also called CAST-128, is a block cipher by Carlisle Adams and Stafford Tavares (1996, RFC 2144) with 40 to 128-bit keys. It was the default cipher of older PGP and GnuPG versions. It uses a 128-bit key (16 rounds) in Cipher Block Chaining mode: each 8-byte block is mixed with the previous encrypted block before it is encrypted.

LegacyCAST5 (CAST-128): Not broken in everyday use, but outdated. Use it to match old systems, not for new ones.

How your secret becomes the key

The default key length is 16 bytes (128 bits). Shorter secrets are padded with zero bytes to 16 bytes. Longer secrets are used in full, because CAST5 accepts variable key lengths.

Where you meet CAST5
  • Older PGP and GnuPG messages
  • Older OpenSSH versions (cast128-cbc)
Honest answer

Is it safe to use?

The cipher: legacy

CAST5. Not broken in everyday use, but outdated. Use it to match old systems, not for new ones.

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?

Cipher Block Chaining

How CBC mode works

CBC splits the text into 8-byte blocks. Before a block is encrypted, it is XORed with the previous encrypted block; the first block is XORed with the IV. So every block depends on all blocks before it.

The last block is filled up with PKCS#7 padding: if 5 bytes are missing, five bytes 05 are added. A text that fills its last block exactly gets a whole extra block of padding. That is why the output is always a multiple of 8 bytes and at least one byte longer than the input.

With a random IV, the same text gives a different result each time. This tool uses no IV (zero bytes), so the same text and secret always give the same result, and the first block is identical to ECB.

Original: 144 blocks of 8 bytes
cast5-ecb
cast5-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 nne63+9U3jeRc2YJ9VpBZQ== 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("6d792073656372657400000000000000"); // "my secret" padded with zero bytes to 16 bytes
$iv  = hex2bin("0000000000000000"); // no IV given: 8 zero bytes
echo openssl_encrypt("hello world", "cast", $key, 0, $iv);

Shortest form, same result: openssl_encrypt("hello world", "cast", "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("6d792073656372657400000000000000")  # "my secret" padded with zero bytes to 16 bytes
iv = bytes(8)  # no IV given: 8 zero bytes
data = "hello world".encode()
padder = padding.PKCS7(64).padder()
data = padder.update(data) + padder.finalize()
enc = Cipher(algorithms.CAST5(key), modes.CBC(iv)).encryptor()
print(base64.b64encode(enc.update(data) + enc.finalize()).decode())

Python has no CAST5 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("6d792073656372657400000000000000", 'hex'); // "my secret" padded with zero bytes to 16 bytes
const iv = Buffer.alloc(8); // no IV given: 8 zero bytes
const c = createCipheriv("cast5-cbc", key, iv);
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.

Command line
printf '%s' 'hello world' | openssl enc -cast5-cbc -K 6d792073656372657400000000000000 -iv 0000000000000000 -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. openssl enc uses at most 16 bytes of -K, so secrets longer than that give a different result here.

Common mistakes

Why your cast 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.

Your code uses a random IV

With a random IV the result changes every time. The tool uses no IV, which in PHP means zero bytes. Use a zero IV of the right length to get the same result, and keep the random IV for real data.

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.

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.

"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 cast.

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

Every CAST5 variant, same input

The text The quick brown fox jumps over the lazy dog (43 bytes) with the secret my secret in all 6 CAST5 ciphers. The last column lists names that give the same result: aliases, and modes that agree for this input. Highlighted: the same start as cast. 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
cast Legacywz37RCnfdgQKPYKjjpen46/DYckXAR5KJzNX9kVg7MiHBRZlD7vWjRrfgJdL07npcast-cbc, cast5-cbc
cast-cbc Legacywz37RCnfdgQKPYKjjpen46/DYckXAR5KJzNX9kVg7MiHBRZlD7vWjRrfgJdL07npcast, cast5-cbc
cast5-cbc Legacywz37RCnfdgQKPYKjjpen46/DYckXAR5KJzNX9kVg7MiHBRZlD7vWjRrfgJdL07npcast, cast-cbc
cast5-cfb LegacyfSq14e1Mfl3gsn/cR96H8+WcmYf412tnNOsNcgb1Chetts6xw1TdzkBy2A==
cast5-ecb Legacywz37RCnfdgRe0UGbzlp3SRuS9qa512T9g/ZnIqnaF/OcBO0G8n+Mc51bf3aBwYiA
cast5-ofb LegacyfSq14e1Mfl2PSwD1onekg6YiHMN9SiMfgBrvKbBQyvxmrLegC1Ppbb/wHA==
Test values

cast 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.

Textcast (Base64)
empty stringan2OX16v8RE=
aWjqRAVLtG8k=
hello worldnne63+9U3jeRc2YJ9VpBZQ==
0123456789abcdefpgz2JngSLhHWwNABelO4ANeENGfUY7dC
The quick brown fox jumps over the lazy dogwz37RCnfdgQKPYKjjpen46/DYckXAR5KJzNX9kVg7MiHBRZlD7vWjRrfgJdL07np
FAQ

Questions about cast

Is cast the same as cast5-cbc?

Yes, in this tool and in PHP on OpenSSL 1.1.1 they give exactly the same result. cast is just another name, so you can decrypt with either.

Can cast be decrypted without the secret?

No. Without the secret there is no shortcut. A short or common secret can be guessed, though, because the tool uses it directly as the key.

Why does my cast 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.

Why do cast5-cbc and cast5-ecb give the same result?

Only for short texts. With a zero IV, the first CBC block equals the ECB block. From the second block on, CBC mixes in the previous block and the results differ.

Is CAST5 secure?

CAST5 is outdated. It is not broken in everyday use, but its 8-byte blocks make it unsafe for large amounts of data (Sweet32) and modern ciphers like AES are better. Use it only for compatibility.

How long should my secret be?

At least 16 bytes, the default key length; longer secrets are used in full. For real security a random key is better than a typed word.

Good to know

Before you rely on it

Background

One click encryption, try our CAST tool now!

Our CAST encryption/decryption tool offers a simple and secure solution for protecting your sensitive information. With just one click, you can easily encrypt or decrypt any string using the powerful and secure CAST algorithm. Whether you need to encrypt files, protect network communication, or secure passwords, our tool makes it easy to safeguard your data. Give it a try now and experience the power of CAST encryption.

CAST Encryption: Understanding the Basics

Encryption is a vital tool for protecting sensitive information, and one encryption algorithm that is gaining popularity is CAST. In this article, we will take a closer look at CAST encryption, including its history, how it works, and where it's commonly used. We will also provide a quick guide on how to use our CAST encryption/decryption tool.

A Brief History of CAST

CAST was developed by Carlisle Adams and Stafford Tavares in 1996. It was designed to be a fast and efficient encryption algorithm that could be used in a wide range of applications. CAST is a symmetric-key encryption algorithm and it is considered to be a very secure encryption method.

How CAST Works

CAST is a symmetric-key block cipher that encrypts data in 64-bit blocks. It uses a variable-length key, from 40 to 128 bits, making it suitable for both domestic and exportable use. CAST uses a complex and unique round function, that makes it resistant to differential and linear cryptanalysis attacks.

Applications of CAST

CAST is suitable for a variety of applications, including:

  • File and disk encryption: CAST can be used to encrypt files and entire disk partitions, providing a high level of protection for sensitive data.
  • Network communication: CAST can be used to encrypt data transmitted over a network, such as in VPNs, SSH, and other secure communication protocols.
  • Authentication: CAST can be used as a one-way hash function for password storage and authentication.

Using our CAST Encryption/Decryption Tool

If you're looking for a quick and easy way to encrypt or decrypt data using CAST, our tool is the perfect solution. With just one mouse click, you can cast encrypt or cast decrypt any string. Give our CAST encryption/decryption tool a try today and see for yourself how easy it is to use!

In conclusion, CAST is an encryption algorithm that was designed to be a fast and efficient encryption algorithm that could be used in a wide range of applications, it's considered a very secure encryption method, it's suitable for a variety of applications and our tool makes it easy for anyone to encrypt or decrypt data using this algorithm.

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