我正在尝试通过openssl进行AES-CBC密码和解密,但是,我无法获得正确的输出。请建议我。谢谢。
CLR; MSG_CIPHERED_HEX =" 920e5af8b78702c778a919f7969a1f8cba578f11693673035213daf02500c50a" IV =" 00000000000000000000000000000000" KEY =#&34; 00000000000000000000000000000000" echo -n" $ MSG_CIPHERED_HEX" | xxd -r -p | openssl enc -aes-128-cbc -K $ KEY -iv $ IV | xxd -p | tr -d' \ n'
CLR;
MSG_CIPHERED_HEX =" 734563526574204d6553734167452030300a0e0e0e0e0e0e0e0e0e0e0e0e0e0e"
echo $ MSG_CIPHERED_HEX
MSG_ASCII = echo $MSG_HEX | xxd -p -r | tr -d '\n'
; echo $ MSG_ASCII> tmp.ciphered.file.ascii;
openssl enc -d -aes-128-cbc -K $ KEY -iv $ IV -in tmp.ciphered.file.ascii -out out.txt
cat out.txt | xxd -p#| tr -d' \ n'
rm -rf tmp.ciphered.file.ascii out.txt
似乎存在数据格式问题: $ #decipher MSG_CIPHERED_HEX =" 920e5af8b78702c778a919f7969a1f8cba578f11693673035213daf02500c50a" IV =" 00000000000000000000000000000000" KEY =#&34; 00000000000000000000000000000000" echo -n" $ MSG_CIPHERED_HEX" | xxd -r -p | openssl enc -d -aes-128-cbc -K $ KEY -iv $ IV | xxd -p | tr -d' \ n'
答: 734563526574204d6553734167452030300a(截断)
$ #cipher MSG_CIPHERED_HEX =" 920e5af8b78702c778a919f7969a1f8cba578f11693673035213daf02500c50a" IV =" 00000000000000000000000000000000" KEY =#&34; 00000000000000000000000000000000" echo -n" $ MSG_CIPHERED_HEX" | xxd -r -p | openssl enc -aes-128-cbc -K $ KEY -iv $ IV | xxd -p | tr -d' \ n'
答: 236999001256bd4131dffa3417c29bfc597a43f6bde387ba0e42da86e67cfff42890e4f6e84c0e70753a9db754df996e
答案 0 :(得分:1)
use std::thread;
use std::cmp::max;
pub fn max_length(input: &[&str], workers: usize) -> usize {
let mut result = 0;
let max_lines_per_worker = (input.len() as f32 / workers as f32).ceil();
let mut handles = Vec::new();
for assigned_lines in input.chunks(max_lines_per_worker as usize) {
let handle = thread::spawn(move || {
let mut count = 0;
for line in assigned_lines {
count = max(count, line.len())
}
count
});
handles.push(handle);
}
for handle in handles {
if let Ok(count) = handle.join() {
result = max(result, count);
}
}
result
}
fn main() {
println!("{:?}", max_length(&LINES, 3));
}
const LINES: [&'static str; 4] = ["abc", "123", "qwerty", "zxcvbnm"];
是14个字节的填充。如果在解密时指定填充,它将自动删除。
请参阅PKCS7 padding。