Развернуть все
Свернуть все

Пример использования

PHP
function SetupStore($location, $name, $mode)
{
    $store = new CPStore();
    $store->Open($location, $name, $mode);
    return $store;
}

function SetupCertificates($location, $name, $mode)
{
    $store = SetupStore($location, $name, $mode);
    return $store->get_Certificates();
}

function SetupCertificate($location, $name, $mode,
                           $find_type, $query, $valid_only,
                           $number)
{
    $certs = SetupCertificates($location, $name, $mode);
    if ($find_type != NULL)
    {
        $certs = $certs->Find($find_type, $query, $valid_only);
        if (is_string($certs))
            return $certs;
        else
            return $certs->Item($number);
    }
    else
    {
        $cert = $certs->Item($number);
        return $cert;
    }
}

try
{
    $content = "test content";
    $tsp_addres = "http://testca.cryptopro.ru/tsp/tsp.srf";
    $cert = SetupCertificate(CURRENT_USER_STORE, "My", STORE_OPEN_READ_ONLY,
                             CERTIFICATE_FIND_SUBJECT_NAME, "test", 0,
                             1);

    if (!$cert)
    {
        printf("Certificate not found\n");
        return;
    }

    $signer = new CPSigner();
    $signer->set_TSAAddress($tsp_addres);
    $signer->set_Certificate($cert);

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

    $sm = $sd->Sign($signer, 0, STRING_TO_UCS2LE);
    printf("Signature is:\n");
    printf($sm);
    printf("\n");
    $sd->Verify($sm, 0, VERIFY_SIGNATURE_ONLY);
    printf("Verify OK\n");
}
catch (Exception $e)
{
    printf($e->getMessage());
}