我正在尝试使用 AES-256-ECB 解密电子邮件地址。这有点困难,因为每个来源都展示了不同的方法,而我得到了不同的结果。当然,我没有得到我想要的结果。请轻松评论我尝试过的代码 - 这个函数现在改变了大约一百万次。
所需的输出:https : //gchq.github.io/CyberChef/#recipe=AES_Encrypt(%7B'option' : 'Hex','string' : '9cc25c7879fc94d5a19eeb8e47573b8423becb608a9a4e9d3c5a70c2'ex' 'string':''%7D,'ECB','Raw','Hex','Ciphertext')AES_Decrypt(%7B'option':'Hex','string':'9cc25c7879fc94d5a19eeb8e47573b8423becb608a30a27a4e' option':'Hex','string':''%7D,'ECB','Hex','Raw',%7B'option':'Hex','string':'undefined'%7D,'' /disabled/breakpoint)&input=dGVzdHVzZXJAZ21haWwuY29t
废话代码:
function my_simple_crypt( $string, $action = 'e' ) {
$secret_key = hex2bin('9cc25c7879fc94d5a19eeb8e47573b8423becb608a9a4e9d3c25c20aa7e04357');
$output = false;
$encrypt_method = "AES-256-ECB";
//$secret_key = openssl_digest($secret_key, $encrypt_method, true);
//$key = hash( 'sha256', $secret_key );
if( $action == 'e' ) {
$output = openssl_encrypt( $string, $encrypt_method, $secret_key, 3 );
//$output = bin2hex($output);
//$output = unpack('H*', $output);
} else if( $action == 'd' ) {
$output = openssl_decrypt( $string, $encrypt_method, $secret_key, 3 );
//$output = base64_encode($output);
$output = bin2hex($output);
}
return $output;
}
echo '<pre>';
print_r(my_simple_crypt( '[email protected]', 'e' ));
echo '</pre>';
echo 'Encrypt: ' . my_simple_crypt( '[email protected]', 'e' ) . '<br>';
echo 'Decrypt: ' . my_simple_crypt( hex2bin('8dd714df21027133cd422d0301af3cb973374ee72008c3f9bd255f6d236da65e'), 'd' );
由于您的密钥和密文采用十六进制编码,您需要将它们转换回二进制数据,然后才能将它们提供给解密函数。
下面的代码给出了这个输出:
plaintext decrypted: [email protected]
plaintext expected: [email protected]
**安全警告:以下代码使用UNSECURE ECB模式:
<?php
$keyHex = '9cc25c7879fc94d5a19eeb8e47573b8423becb608a9a4e9d3c25c20aa7e04357';
$ciphertextHex = '8dd714df21027133cd422d0301af3cb973374ee72008c3f9bd255f6d236da65e';
$plaintextExpected = '[email protected]';
$key = hex2bin($keyHex);
$ciphertext = hex2bin($ciphertextHex);
$plaintext = openssl_decrypt($ciphertext, 'aes-256-ecb', $key, true);
echo 'plaintext decrypted: ' . $plaintext . PHP_EOL;
echo 'plaintext expected: ' . $plaintextExpected . PHP_EOL;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句