Module encryption

Module encryption 

Source
Expand description

DES Encryption support for ZUS RPC protocol

This module provides DES-ECB encryption/decryption compatible with the C++ and Java ZUS implementations.

§Encryption Details

  • Algorithm: DES (Data Encryption Standard)
  • Mode: ECB (Electronic Codebook)
  • Padding: Zero-padding to 8-byte blocks
  • Key size: 8 bytes (64 bits, with 56 effective bits)

§Cross-Language Compatibility

This implementation is compatible with:

  • C++: zus::DesEncrypt class in des.cpp
  • Java: CryptUtil.desEncrypt() / CryptUtil.desDecrypt() in CryptUtil.java

§Example

use zus_common::encryption::{DesEncryptor, encrypt_des, decrypt_des};

// Using the simple functions
let key = b"12345678";
let plaintext = b"Hello, World!";
let encrypted = encrypt_des(plaintext, key).unwrap();
let decrypted = decrypt_des(&encrypted, key).unwrap();
assert_eq!(&decrypted[..plaintext.len()], plaintext);

// Using the DesEncryptor for multiple operations
let encryptor = DesEncryptor::new(key);
let encrypted = encryptor.encrypt(plaintext).unwrap();
let decrypted = encryptor.decrypt(&encrypted).unwrap();

Structs§

DesEncryptor
DES Encryptor for encrypting and decrypting data using DES-ECB mode.

Constants§

DES_BLOCK_SIZE
DES block size in bytes
DES_KEY_SIZE
DES key size in bytes

Functions§

decrypt_des
Decrypt data using DES-ECB mode.
encrypt_des
Encrypt data using DES-ECB mode with zero-padding.