79240414

Date: 2024-11-30 20:16:54
Score: 0.5
Natty:
Report link

Thanks to @topaco 's comment the solution is found. The code was quite close, it simply did not need the key to be decoded as Base64.

Here's the result code:

use aes::cipher::{block_padding::Pkcs7, BlockDecryptMut, KeyInit};
use base64::Engine;
use base64::engine::general_purpose;

type Aes128EcbDec = ecb::Decryptor<aes::Aes128>;
async fn test_decryption() {
    let key = "KeyIs16CharsLong";
    let plaintext = "nFWwLNMi2toxug1hDb/HGg==";

    // Decode key 
    let key_bytes = key.as_bytes();

    // Convert ciphertext from hex to bytes
    let mut ciphertext = general_purpose::STANDARD.decode(plaintext).expect("Invalid Base64 ciphertext");

    let pt = Aes128EcbDec::new_from_slice(key_bytes)
        .unwrap()
        .decrypt_padded_mut::<Pkcs7>(&mut ciphertext)
        .unwrap();

    // Convert decrypted plaintext to a string
    let decrypted_plaintext = String::from_utf8(pt.to_vec()).expect("Decryption produced invalid UTF-8");
    println!("Decrypted plaintext: {}", decrypted_plaintext);
}
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Whitelisted phrase (-1): solution is
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @topaco
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Captain Ildar