pub struct Cryptor { /* private fields */ }Expand description
A cryptographic utility for encrypting and decrypting text using a matrix-based transformation.
The Cryptor uses a combination of shuffling, mixing, and matrix operations to obscure the
original text. It supports configurable matrix sizes for the transformation process.
§Examples
use crypt_ro::Cryptor;
let cryptor = Cryptor::new();
let encrypted = cryptor.encrypt_text("secret message", "password").unwrap();
let decrypted = cryptor.decrypt_text(&encrypted, "password").unwrap();
assert_eq!(decrypted, "secret message");Implementations§
Source§impl Cryptor
impl Cryptor
Sourcepub fn encrypt(&self, data: &[u8], key: &str) -> Result<Vec<u8>, Box<dyn Error>>
pub fn encrypt(&self, data: &[u8], key: &str) -> Result<Vec<u8>, Box<dyn Error>>
Encrypts raw bytes using the provided key.
§Arguments
data- The bytes to encryptkey- The encryption key
§Returns
A Result containing the encrypted bytes or an error if encryption fails.
§Example
use crypt_ro::Cryptor;
let cryptor = Cryptor::new();
let encrypted = cryptor.encrypt(b"secret data", "key123").unwrap();
assert!(!encrypted.is_empty());Sourcepub fn encrypt_text(
&self,
text: &str,
key: &str,
) -> Result<String, Box<dyn Error>>
pub fn encrypt_text( &self, text: &str, key: &str, ) -> Result<String, Box<dyn Error>>
Encrypts raw bytes using the provided key.
§Arguments
text- The plaintext to encryptkey- The encryption key
§Returns
A Result URL-safe base64 string without padding or an error if encryption fails.
§Example
use crypt_ro::Cryptor;
let cryptor = Cryptor::new();
let encrypted = cryptor.encrypt_text("secret message", "password").unwrap();
assert!(!encrypted.contains('/')); // URL-safeSourcepub fn decrypt(
&self,
encoded: &Vec<u8>,
key: &str,
) -> Result<Vec<u8>, Box<dyn Error>>
pub fn decrypt( &self, encoded: &Vec<u8>, key: &str, ) -> Result<Vec<u8>, Box<dyn Error>>
Decrypts bytes using the provided key.
§Arguments
encoded- The encrypted bytes to decryptkey- The decryption key
§Returns
A Result containing the decrypted bytes or an error if decryption fails.
§Example
use crypt_ro::Cryptor;
let cryptor = Cryptor::new();
let encrypted = cryptor.encrypt(b"data", "key").unwrap();
let decrypted = cryptor.decrypt(&encrypted, "key").unwrap();
assert_eq!(decrypted, b"data");Sourcepub fn decrypt_text(
&self,
encoded: &str,
key: &str,
) -> Result<String, Box<dyn Error>>
pub fn decrypt_text( &self, encoded: &str, key: &str, ) -> Result<String, Box<dyn Error>>
Decrypts a URL-safe base64 encoded string using the provided key.
§Arguments
encoded- A URL-safe base64 encoded string to decryptkey- The decryption key
§Returns
A Result containing the decrypted string or an error if decryption fails.
§Example
use crypt_ro::Cryptor;
let cryptor = Cryptor::new();
let encrypted = cryptor.encrypt_text("message", "pass").unwrap();
let decrypted = cryptor.decrypt_text(&encrypted, "pass").unwrap();
assert_eq!(decrypted, "message");Sourcepub fn set_matrix(&mut self, size: usize)
pub fn set_matrix(&mut self, size: usize)
Sets the matrix size used for cryptographic operations.
The matrix size determines how data is chunked and processed during encryption/decryption. Must be a positive non-zero value.
§Example
use crypt_ro::Cryptor;
let mut cryptor = Cryptor::new();
cryptor.set_matrix(64); // Use larger blocks