AES Encryption and Decryption Online: CBC, ECB, Keys, and IVs
Summary:Use AES-128, AES-192, or AES-256 with CBC or ECB in your browser. Check UTF-8 key lengths, IV requirements, and hex or Base64 ciphertext encoding.

When integrating an API or debugging encryption settings, an independent ciphertext calculation can help. Xian's Tools provides two AES tools:

Both tools run in your browser. Your input and keys are not sent to a processing server.

Parameters for the standard AES tool

- Key Size:128、192 或 256;决定所需的密钥长度(以字节为单位)。

- Cipher Mode:CBC 或 ECB。CBC 使用 IV;ECB 不使用。

- Key:按 UTF-8 字节解释的文本。

- iv:仅在 CBC 模式下显示的文本。

- Encode Format:hex、base64 或 utf8。加密时,这是密文的输出编码;解密时,这是密文的输入编码。

该工具使用 PKCS#7 填充。Java 提供程序通常以 PKCS5Padding 这一名称公开等效的 AES 填充行为。

Required key lengths

UTF-8 密钥长度必须恰好为:

  • AES-128:16 字节,例如 16 个 ASCII 字母或数字。
  • AES-192:24 字节。
  • AES-256:32 字节。

许多常见中文字符在 UTF-8 中占三个字节,因此字符数与字节数不同。如果密钥长度不正确,该工具会报告所需的字节数,而不会对密钥进行填充或截断。

IV requirements

  • 在 CBC 模式下,IV 必须为 16 个 UTF-8 字节。
  • 将 IV 留空会使用 16 个零字节。这与输入十六个 ASCII 0 字符不同。

How to use it

1. Enter plaintext under Original Content, or ciphertext when decrypting.

2. Enter the Key and select the matching Key Size.

3. Select Cipher Mode and enter the IV for CBC if needed.

4. Choose Encode Format, usually base64 or hex.

5. Click Encrypt or Decrypt, then copy the result.

CBC and ECB compared

  • ECB encrypts each block independently. Identical plaintext blocks produce identical ciphertext blocks, exposing patterns. Use it only when a legacy integration requires it rather than choosing it for a new design.
  • CBC combines each plaintext block with the previous ciphertext block before encryption. An IV initializes the process. For actual message encryption, use a fresh unpredictable IV and transmit it with the ciphertext. CBC alone does not authenticate the message.

Hex and Base64 ciphertext

Both encodings represent binary ciphertext as printable text:

  • hex uses two characters per byte, from 0-9 and a-f.
  • base64 is roughly two-thirds the length of hex for larger inputs and is often used in JSON or HTTP payloads.

**To Upper Case** can be used for hex output. **Base64 is case-sensitive: changing its case changes the encoded bytes and can prevent decryption.** The utf8 option is generally unsuitable for ciphertext because arbitrary encrypted bytes are not necessarily valid UTF-8 text.

Troubleshooting mismatched results

  1. **Mode**: CBC and ECB produce different results.
  2. **Key size**: verify that both implementations use the same AES variant and key bytes.
  3. **IV**: check for a zero IV, a random IV, or an IV prefixed to the ciphertext.
  4. **Padding**: NoPadding or ZeroPadding will not match this tool's padding behavior.
  5. **Encoding**: check hex versus Base64. A key displayed as hex or Base64 may need decoding elsewhere; this tool treats the Key field as UTF-8 text.
  6. **Plaintext**: check for extra spaces, line breaks, and encoding differences.

The passphrase tool

AES Passphrase Encryption accepts input text and a Key used as a passphrase. Click Encrypt to obtain Base64 ciphertext.

  • The passphrase does not need the standard AES key length. CryptoJS derives a key and IV from the passphrase and a random salt.

The same input and passphrase usually produce different ciphertext on each encryption

Each result can still be decrypted using the same passphrase, because the salt changes.

  • Ciphertext commonly starts with U2FsdGVkX1, associated with the OpenSSL-style salted format used by CryptoJS.
  • The workflow matches CryptoJS.AES.encrypt(text, passphrase) with compatible settings.

This is useful for testing projects that use the same CryptoJS passphrase workflow. For comparisons with an implementation that accepts a raw AES key and IV, use the standard AES tool.

Notes for encryption testing

  • Use test keys when learning or debugging, and keep production keys protected.
  • Avoid pasting sensitive keys into websites you do not trust.
  • For new production systems, consider an authenticated mode such as AES-GCM and use an established library to generate the required random keys and IVs. This page's standard tool provides CBC and ECB, not GCM.

Related tools

上一节介绍了 Random String Generator。这一节继续整理常用工具的入口与索引。

工具索引

如果只记住一个入口,就记住 Random String Generator,从它出发可以继续访问其他转换、压缩与编码工具。

  • 图像:压缩、转换、裁剪
  • 视频:转换、裁剪、截取片段
  • 音频:转换、截取片段、提取与压缩
  • 编码与安全:QR 码、AES、哈希

所有处理均在浏览器本地完成,文件不会上传。

至此全文结束。

Questions
Compress JPG and PNG Images Online Without Uploading Files
Reduce JPG and PNG file sizes in your browser. Learn how quality settings, output formats, and compression ratios affect your images.
Convert PNG to JPG and JPG to PNG Online
Convert PNG, JPG, and BMP images in your browser without uploading files. Learn how conversion affects transparency, file size, and image quality.
Crop Images Online: Aspect Ratios, Rotation, and WebP Export
Crop photos to 1:1, 16:9, and other aspect ratios. Rotate, flip, and lock your selection, then export PNG, JPG, or WebP directly in your browser.
Resize Images, View Image Information, and Create ICO Icons Online
Resize images, adjust output quality, inspect format and color space, and convert PNG or JPG to ICO icons with browser-based Image Tools.
Convert MOV to MP4, MKV to MP4, and MP4 to WebM Online
Convert videos between MP4, MKV, AVI, MOV, FLV, WebM, and M4V in your browser. Compare formats and learn what changes during conversion.
Trim and Crop Videos Online, Then Export MP4
Keep a selected video segment, remove black borders, or crop a recording to one area. Trim and crop locally in your browser and download an MP4.
Extract Audio from Video Online: Convert MP4 to MP3
Extract sound from MP4, MOV, or MKV videos and export MP3, WAV, FLAC, or M4A. Process recordings locally in your browser without uploading files.
Convert WAV, FLAC, and M4A to MP3 Online
Convert audio between MP3, WAV, FLAC, M4A, OGG, WMA, and AC3 in your browser. Compare formats and understand the tradeoffs in file size and quality.
Trim Audio Online: Cut MP3 Clips with a Waveform Preview
Select a time range on an audio waveform, listen to the preview, and export MP3. Make short clips or remove unwanted sections from recordings locally.
Generate and Read QR Codes Online from Text, Links, and Images
Create a downloadable QR code from text or a URL, or decode a QR image in your browser. Learn how to make codes easier to scan and inspect their links.
AES Encryption and Decryption Online: CBC, ECB, Keys, and IVs
Use AES-128, AES-192, or AES-256 with CBC or ECB in your browser. Check UTF-8 key lengths, IV requirements, and hex or Base64 ciphertext encoding.
Base64 and URL Encoding Online: Differences and Common Uses
Encode and decode UTF-8 text with Base64 or URL percent-encoding in your browser. Learn which to use and how to troubleshoot malformed URL escapes.
Random String Generator: Alphanumeric Test Data and Temporary IDs
Generate 1–10,000 alphanumeric characters with a letter first. Create test data and temporary identifiers, and learn why this tool is unsuitable for secrets.
Free Online Tools for Images, Video, Audio, and Encoding
Explore Xian's Tools for compression, conversion, trimming, QR codes, AES, and hashing. Learn how files are processed locally in your browser without uploads.
Compress Videos Online: MP4 Compression, Bitrate, and File Size
Compress MP4, MOV, and MKV videos locally in your browser. Learn how the quality slider changes bitrate and how to interpret the estimated output size.
Compress Audio Online: Reduce MP3 Bitrate and Recording File Size
Reduce audio file sizes locally in your browser. Learn how bitrate affects size and how to choose compression settings for speech, podcasts, and music.
Calculate MD5, SHA, and HMAC Online: Uses and Differences
Calculate MD5, SHA1, SHA256, SHA512, and HMAC for text in your browser. Understand digest lengths, API signatures, and why hashing is not encryption.