Text

AES Advanced Encryption

0calls
1 credits / call

Need a more flexible AES encryption solution? This advanced endpoint supports 6 encryption modes and 3 padding methods, allowing you to choose the most suitable encryption configuration for your specific scenario.

POST
uapis.cn
/api/v1/text/aes/encrypt-advanced
Body
text
string
required

Plaintext text to be encrypted

key
string
required

Encryption key (supports any length)

mode
string

Encryption mode: GCM/CBC/ECB/CTR/OFB/CFB (optional, default GCM)

padding
string

Padding method: PKCS7/ZERO/NONE (optional, default PKCS7)

iv
string

Custom IV (optional, Base64 encoded, 16 bytes). GCM mode does not require this parameter

output_format
string

Output format: base64 (default) or hex

Important

GCM Mode Recommended GCM mode provides authenticated encryption (AEAD), which not only encrypts data but also verifies data integrity, preventing ciphertext tampering. This is currently the most recommended encryption mode.

Overview

This is a comprehensive AES encryption endpoint supporting multiple encryption modes and padding methods. You can flexibly choose appropriate encryption configurations based on different security requirements and performance needs.

Supported Encryption Modes

  • GCM Mode (Recommended): Authenticated encryption mode, providing integrity protection
  • CBC Mode: Classic block encryption mode, requires IV and padding, suitable for file encryption
  • CTR Mode: Stream cipher mode, no padding required, suitable for real-time data encryption
  • OFB/CFB Mode: Stream cipher mode, no padding required, suitable for stream data encryption
  • ECB Mode (Not recommended): Only for compatibility requirements

Supported Padding Methods

  • PKCS7 Padding (Recommended): Standard padding method
  • Zero Padding: Uses 0x00 bytes for padding
  • None Padding: No padding, used for stream cipher modes

Output Format Support

  • base64 (Default): Standard Base64 encoded output, suitable for transmission and storage
  • hex: Hexadecimal encoded output, convenient for result verification

The output_format parameter allows direct retrieval of HEX format ciphertext without additional conversion endpoint calls.

Parameter Description

  • text: Plaintext text to be encrypted
  • key: Encryption key (supports any length)
  • mode: Encryption mode (optional, default GCM)
  • padding: Padding method (optional, default PKCS7)
  • iv: Custom IV (optional, Base64 encoded, 16 bytes)
  • output_format: Output format (optional, default base64)

Usage Examples

Example 1: HEX Format Output

JSON
{
  "text": "Test text 123",
  "key": "1234567890123456",
  "mode": "ECB",
  "padding": "PKCS7",
  "output_format": "hex"
}

Response example:

JSON
{
  "ciphertext": "aaaca6027da10918bb5d23d81939552c",
  "mode": "ECB",
  "padding": "PKCS7"
}

Example 2: Base64 Format Output (Default)

JSON
{
  "text": "Test text 123",
  "key": "1234567890123456",
  "mode": "ECB",
  "padding": "PKCS7"
}

Response example:

JSON
{
  "ciphertext": "qqymAn2hCRi7XSPYGTlVLA==",
  "mode": "ECB",
  "padding": "PKCS7"
}

Technical Specifications

  • Encryption Algorithm: AES-256
  • Encoding Format: Base64/HEX (input/output)
  • IV Length: 16 bytes (128 bits)
Note

About IV (Initialization Vector)

  • GCM mode does not require IV
  • CBC/CTR/OFB/CFB modes can optionally provide IV
  • ECB mode does not use IV
  • It is recommended to use different IVs for each encryption to ensure security
Tip

About Output Format

  • For verifying output results, it is recommended to use output_format: "hex"
  • Base64 format is more suitable for network transmission and API calls
  • Both formats can be converted to each other, data is completely consistent

Request body

text
stringrequired

Plaintext text to be encrypted

key
stringrequired

Encryption key (supports any length)

mode
stringoptional

Encryption mode: GCM/CBC/ECB/CTR/OFB/CFB (optional, default GCM)

padding
stringoptional

Padding method: PKCS7/ZERO/NONE (optional, default PKCS7)

iv
stringoptional

Custom IV (optional, Base64 encoded, 16 bytes). GCM mode does not require this parameter

output_format
stringoptional

Output format: base64 (default) or hex

Response

200 / OK

Encryption successful, returns ciphertext and encryption configuration

JSON
{
  // Encrypted ciphertext (Base64 encoded)
  "ciphertext": "kJB3X5YxNzA2MTA1NDQ3Mjc3ODg5...",
  // Encryption mode used
  "mode": "GCM",
  // Padding method used
  "padding": "NONE",
  // IV used (Base64 encoded). GCM mode does not return this field
  "iv": "cmFuZG9tSVZoZXJl"
}

400 / Bad Request

Invalid request parameters

JSON
{
  "error": "Unsupported encryption mode: INVALID"
}