在PHP文件中使用openssl的SMIME解密错误

时间:2019-03-02 15:04:23

标签: php encryption smime

我正在开发PHP代码以解密和加密通过http通信接收的消息。现在,我在解密合作伙伴通过HTTP通信发送的SMIME消息时遇到错误。你能帮我解决这个问题吗

这是解密中产生错误的代码块的一部分

httpSec.authorizeRequests()
    .antMatchers("/welcomeUrl").permitAll()
    .antMatchers("/user/**").hasAuthority("ADMIN").anyRequest()
    .authenticated()
    .and().httpBasic()
    .sessionManagement().maximumSessions(1).expiredUrl("/welcomeUrl");

当我运行这段代码时,我遇到了错误

public function decrypt($input){
        /*file_put_contents('/tmp/decrypt', '---------------------------------------------------------------'."\n", FILE_APPEND);
        file_put_contents('/tmp/decrypt', 'try to decrypt file :'."\n", FILE_APPEND);
        file_put_contents('/tmp/decrypt', '---------------------------------------------------------------'."\n", FILE_APPEND);
        file_put_contents('/tmp/decrypt', print_r(file_get_contents($input), true)."\n", FILE_APPEND);*/

        try {
            $private_key = self::getPrivateFromPKCS12($this->partner_to->sec_pkcs12, $this->partner_to->sec_pkcs12_password, '');
            if (!$private_key)
                throw new AS2Exception('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 '    . 
                                            ' -decrypt ' . 
                                            ' -in '      . escapeshellarg($input) . 
                                            ' -inkey '   . escapeshellarg($private_key) . 
                                            ' -out '     . escapeshellarg($output);

            // seems to generate non-conform message
            /*$security = ' -pkcs12 '.escapeshellarg($this->partner_to->sec_pkcs12).
                ($this->partner_to->sec_pkcs12_password?' -password '.escapeshellarg($this->partner_to->sec_pkcs12_password):' -nopassword');

            $command = self::$javapath.' -jar '.escapeshellarg(AS2_DIR_BIN.self::$ssl_adapter).
                                       ' decrypt'.
                                       $security.
                                       ' -in '.escapeshellarg($input).
                                       ' -out '.escapeshellarg($output).
                                       ' >/dev/null';*/

            $result = $this->exec($command);

            return $output;
        }
        catch(Exception $e){
            throw $e;
        }
    }

如果您需要其他详细信息,请告诉我。

0 个答案:

没有答案