Decrypting using openssl des-ede from the command-line with zero padding and raw data

筅森魡賤 提交于 2020-01-17 05:53:04

问题


I am trying to recreate some openssl php code in the command-line. I have been able to get the following php code to work:

$key = 'aaaaaaaabbbbbbbbccccccccdddddddd';
$key = pack('H*',$key);

$data = 'b5057bbc04b842a96144a0f617f2820e';
$data = pack('H*',$data);

$result = openssl_decrypt($data,'des-ede', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);

The Command I'm Working on (Ubuntu)

openssl des-ede -in encrypted-data.txt -out decrypted-data.txt -d -K aaaaaaaabbbbbbbbccccccccdddddddd -nopad

The Key

The key that im decrypting with is the hex value: aaaaaaaabbbbbbbbccccccccdddddddd. Can this key be passed as hex?

The Encrypted Data

The encrypted data I am passing in the encrypted-data.txt file is the hex value: b5057bbc04b842a96144a0f617f2820e. The data should decrypt to Test123123. I have tried converting the encrypted data to binary and passing it through a .bin file without success. Should this data be converted to some other format before being passed?

The Parameters

I believe I am having an issue translating the php parameters OPENSSL_RAW_DATA and OPENSSL_ZERO_PADDING to my command-line call. I have discovered the option -nopad, but am unsure if it is equivalent to the options in php


回答1:


I'm only including this here since I can't format a comment and this question should probably be closed and deleted. This verifies the process works identically with the command line openssl utility

pvg /tmp ➤  more e.php 
<?php
$data = 'b5057bbc04b842a96144a0f617f2820e';
$data = pack('H*',$data);

echo $data;
pvg /tmp ➤  php e.php > in
pvg /tmp ➤  openssl des-ede -in in -out out -d -K aaaaaaaabbbbbbbbccccccccdddddddd -nopad
pvg /tmp ➤  cat out
Test123123%    


来源:https://stackoverflow.com/questions/41306800/decrypting-using-openssl-des-ede-from-the-command-line-with-zero-padding-and-raw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!