Справочная информация: я пытаюсь реализовать функциональность связи AS2 используя PHP-код AS2Secure. Когда я пытаюсь отправить сообщение партнеру после подписания и шифрования. Но во время шифрования оно не шифруется, мы отправляем только подписанное сообщение.
Здесь я предоставляю функцию шифрования, которая вызывает внутреннюю функцию exec, как показано ниже
Код: Выделить всё
public function encrypt($input, $cypher = 'des3'){
try {
if (!$this->partner_to->sec_certificate)
$certificate = self::getPublicFromPKCS12($this-
>partner_to->sec_pkcs12, $this->partner_to->sec_pkcs12_password);
else
$certificate = $this->partner_to->sec_certificate;
if (!$certificate) throw new Exception('Unable to
extract private key from PKCS12 file. (' . $this->partner_to-
>sec_pkcs12.' - using:' . $this->partner_to-
>sec_pkcs12_password.')');
$output = self::getTempFilename();
$command = self::$ssl_openssl . ' smime ' .
' -encrypt' .
' -in ' .
escapeshellarg($input) .
' -out ' .
escapeshellarg($output) .
' -des3 ' .
escapeshellarg($certificate);
$result = $this->exec($command);
AS2Log::info(false, 'Encryption successful');
$headers = 'Content-Type: application/pkcs7-mime;
smime-
type="enveloped-data"; name="smime.p7m"' . "\n" .
'Content-Disposition: attachment;
filename="smime.p7m"' . "\n" .
'Content-Transfer-Encoding: binary' . "\n\n";
$content = file_get_contents($output);
// we remove header auto-added by openssl
$content = substr($content, strpos($content, "\n\n") +
2);
$content = base64_decode($content);
$content = $headers . $content;
file_put_contents($output, $content);
/* if ($this->partner_to->sec_pkcs12)
$security = ' -pkcs12 '.escapeshellarg($this-
>partner_to->sec_pkcs12).
($this->partner_to-
>sec_pkcs12_password?' -password '.escapeshellarg($this-
>partner_to->sec_pkcs12_password):' -nopassword');
else
$security = ' -cert '.escapeshellarg($this-
>partner_to->sec_certificate);
$command = self::$javapath.' -jar
'.escapeshellarg(AS2_DIR_BIN.self::$ssl_adapter).
' encrypt'.
$security.
// ' -cypher
'.escapeshellarg($cypher).
' -in
'.escapeshellarg($input).
' -out
'.escapeshellarg($output);
$result = $this->exec($command);*/
return $output;
}
catch(Exception $e){
throw $e;
}
}
Код: Выделить всё
openssl smime -encrypt -in
"C:\\Users\\Maggy\\AppData\\Local\\Temp\\as2A5B3.tmp" -out
"C:\\Users\\Maggy\\AppData\\Local\\Temp\\as2B18B.tmp" -des3
"D:\\as2secure_code_build-
0.9.0\\partners\\maggy\\clientcertificate.pem"
успешно выдала результат.
Вот PHP-код:
Код: Выделить всё
public static function exec($command, $return_output = false){
$output = array();
$return_var = 0;
try{
AS2Log::info(false, 'This is AS2Adapter File and IN EXEC
FUNCTION CALLED'.$command);
// AS2Log::info(false, 'INPUT DATA as FOLLOWS'.file_get_contents($input));
exec($command , $output, $return_var);
// proc_open($command , $output, $return_var);
// passthru ("$command , 2>&1");
AS2Log::info(false, 'This is AS2Adapter File and IN EXEC
FUNCTION EXECUTED and Result will
be ~~~~~~~~~~~~~~~~~~~~~');
AS2Log::info(false, 'This is AS2Adapter File and IN EXEC
FUNCTION COMPLETED
SUCCESSFULLY'.$output[0]);
$line = (isset($output[0])?$output[0]:'Unexpected error in
command line : ' . $command);
if ($return_var) throw new Exception($line,
(int)$return_var);
}
catch(Exception $e){
throw $e;
}
AS2Log::info(false, 'This is RETURN OUTPUT LOOKS LIKE :
'.file_get_contents($output));
AS2Log::info(false, 'This is RETURN VAR LOOKS LIKE :
'.file_get_contents($return_var));
if ($return_output){
return $output;
AS2Log::info(false, 'This is AS2Adapter File and FINAL OUTPUT
LOOKS LIKE : '.$output);
}
else
return $return_var;
}
Я попробовал shell_exec, и он дает тот же результат.
Я попробовал команду passthru, но она не дала никакого результата.
Я пытаюсь подписать и зашифровать сообщение, но это только подпись сообщения, а не шифрование.
Подробнее здесь: https://stackoverflow.com/questions/791 ... t-return-v