des1roer
@des1roer
ученье - свет, а неученье - приятный полумрак

Crypto Pro PHP как подписать файл?

Криптопровайдер установлен на линукс, хеширование работает

Пробую использовать пример

https://docs.cryptopro.ru/cades/phpcades/phpcades-...

//Вспомогательные функции предварительной инициализации

    public function SetupCertificate(
        $location,
        $name,
        $mode,
        $find_type,
        $query,
        $valid_only,
        $number
    ) {
        $certs = $this->SetupCertificates($location, $name, $mode);

        if (!is_null($find_type)) {
            $certs = $certs->Find($find_type, $query, $valid_only);
            return $certs->Item($number);
        } else {
            $cert = $certs->Item($number);
            return $cert;
        }
    }

    public function SetupCertificates($location, $name, $mode)
    {
        $store = $this->SetupStore($location, $name, $mode);
        $certs = $store->get_Certificates();

        return $certs;
    }

    public function SetupStore($location, $name, $mode): CPStore
    {
        $store = new \CPStore();
        $store->Open($location, $name, $mode);

        return $store;
    }

    public function testSign(): void
    {

        $content = 'test content';
        $address = 'http://testca.cryptopro.ru/tsp/tsp.srf';
        $cert = $this->SetupCertificate(
            \app\components\HashService::CURRENT_USER_STORE,
            'My',
            \app\components\HashService::STORE_OPEN_READ_ONLY,
            \app\components\HashService::CERTIFICATE_FIND_SUBJECT_NAME,
            'CN',
            0,
            1,
        );

        if (!$cert) {
            throw new \Exception('Certificate not found');
        }
        $signer = new \app\Proxies\CPSigner();
        $signer->set_TSAAddress($address);
        $signer->set_Certificate($cert);

        $sd = new \app\Proxies\CPSignedData();
        $sd->set_Content($content);

        $sm = $sd->Sign($signer, 0, ENCODE_BASE64);
     }

Установил корневой серт, личный и открытый от третьих лиц.

Ошибка

[Exception] Cannot find the certificate and private key for decryption.
(0x8009200B)
  • Вопрос задан
  • 509 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы