Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7663017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:56:57+00:00 2026-05-31T13:56:57+00:00

I want to use the PHP function openssl_verify() to verify the signatures of different

  • 0

I want to use the PHP function openssl_verify() to verify the signatures of different X.509 certificates.

I have all it needs (certificate, $data, $signature, $pub_key_id) except of the signature algorithm but which is stored in the certificate.

enter image description here

My simple question is: How can I extract signature algorithm from certificates?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:56:58+00:00Added an answer on May 31, 2026 at 1:56 pm

    Look at this question, you can do it similar, try this:

    private function GetCertSignatureAlgorithm($certSignatureBinary, $pubKeyResourceId)
    {
    
    if(false === openssl_public_decrypt($certSignatureBinary, $sigString, $pubKeyResourceId))
    {
        return false;
    }
    
    if (empty($sigString) ||
        strlen($sigString) < 5)
    {
        return false;
    }
    
    if (ord($sigString[0]) !== 0x30 ||
        ord($sigString[2]) !== 0x30 ||
        ord($sigString[4]) !== 0x06)
    {
        return false;
    }
    
    $sigString  = substr($sigString, 4);
    $len        = ord($sigString[1]);
    $bytes      = 0;
    
    if ($len & 0x80)
    {
        $bytes = ($len & 0x7f);
        $len = 0;
        for ($i = 0; $i < $bytes; $i++)
        {
            $len = ($len << 8) | ord($sigString[$i + 2]);
        }
    }
    
    $oidData = substr($sigString, 2 + $bytes, $len);
    $hashOid = floor(ord($oidData[0]) / 40) . '.' . ord($oidData[0]) % 40;
    
    $value = 0;
    for ($i = 1; $i < strlen($oidData); $i++)
    {
        $value = $value << 7;
        $value = $value | (ord($oidData[$i]) & 0x7f);
        if (!(ord($oidData[$i]) & 0x80))
        {
            $hashOid .= '.' . $value;
            $value = 0;
        }
    }
    
    //www.iana.org/assignments/hash-function-text-names/hash-function-text-names.xml
    //www.php.net/manual/en/openssl.signature-algos.php
    switch($hashOid)
    {
        case '1.2.840.113549.2.5':     return 'md5';
        case '1.3.14.3.2.26':          return 'sha1';
        case '2.16.840.1.101.3.4.2.1': return 'sha256';
        case '2.16.840.1.101.3.4.2.2': return 'sha384';
        case '2.16.840.1.101.3.4.2.3': return 'sha512';
    
        //not secure = not accepted
        //case '1.2.840.113549.2.2':     //'md2';
        //case '1.2.840.113549.2.4':     //'md4';
        //case '1.3.14.3.2.18':          //'sha';
    }
    
    throw new Exception('CertSignatureAlgorithm not found');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to use php's json_encode function to take data and produce the following
I want to use boost::crc so that it works exactly like PHP's crc32() function.
I want to use this function: http://www.frankmacdonald.co.uk/php/post-to-wordpress-with-php.html Its used to post to Wordpress using
Hi have some forms that I want to use some basic php validation (regular
I want to use my custom PHP function CalculateAge which takes 3 parameters (day,
I want to use php to create a snapshot of all the files in
I want to use PHP and MySQL to insert data into a data table
I want to use PHP to replace javascript functions in HTML documents. For example:
I want to use php in console mode and create an environment to test
Why would I want to use PHP's filter library? Why wouldn't I? It seems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.