Skip to content

Предлагаю реализовать вычисление хэша сертификата по алгоритму ГОСТ #8

@gatepavel

Description

@gatepavel

Чтобы не пользоваться утилитой cpverify, можно вычислить хэш сертификата по алгоритму ГОСТ самостоятельно.

Примерно это так может выглядеть:

public function getGostHash()
    {
        $store = new \CPStore();
        $store->Open(CURRENT_USER_STORE, 'My', STORE_OPEN_READ_ONLY);

        $certificates = $store->get_Certificates();
        $found = $certificates->Find(CERTIFICATE_FIND_SHA1_HASH, $this->thumbprint, 0);
        if ($found->Count() === 0) {
            throw new SignException("Not found certificate with thumbprint $this->thumbprint");
        }
        $certificate = $found->Item(1);
        if ($certificate->HasPrivateKey() === false) {
            throw new SignException('Cannot read the private key');
        }

        if ($this->pin) {
            $certificate->PrivateKey()->set_KeyPin($this->pin);
        }

        $hashedData = new \CPHashedData();
        $hashedData->set_Algorithm(\CADESCOM_HASH_ALGORITHM_CP_GOST_3411_2012_256);
        $hashedData->set_DataEncoding(\BASE64_TO_BINARY);

        $hashedData->Hash($certificate->Export(\ENCODE_BASE64));

        return $hashedData->get_Value(); 
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions