Module utils

Source
Expand description

§Utility Functions for Cryptographic Operations

This module provides common utility functions used throughout the RusCrypt library, including encoding/decoding, padding, and character manipulation functions.

§Features

  • Encoding: Base64 and hexadecimal encoding/decoding
  • Padding: PKCS#7 padding for block ciphers
  • Character operations: Caesar cipher character shifting

§Examples

use ruscrypt::utils::{to_base64, from_base64, to_hex, from_hex};
 
let data = b"Hello, World!";
let base64 = to_base64(data);
let decoded = from_base64(&base64).unwrap();
assert_eq!(data, &decoded[..]);

Functions§

from_base64
Decodes a Base64 string to binary data.
from_hex
Converts a hexadecimal string to binary data.
pad_data
Pads data to 16-byte blocks using PKCS#7 padding.
pad_data_to_size
Pads data to the specified block size using PKCS#7 padding.
remove_padding
Removes PKCS#7 padding from padded data.
shift_char
Shifts a single character by the specified amount for Caesar cipher.
to_base64
Encodes binary data to a Base64 string.
to_hex
Converts binary data to a lowercase hexadecimal string.