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

  • SEARCH
  • Home
  • 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 8612415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:37:14+00:00 2026-06-12T04:37:14+00:00

I have a Javascript that is signing a text string in the browser. It

  • 0

I have a Javascript that is signing a text string in the browser. It uses CAPICOM under Internet Explorer and window.crypto under Mozilla browsers. After the signing process I receive a BASE64 encoded signature.

Using HTTPS I upload the signature and the text string to a webserver with a PHP application. From the SSL (HTTPS) I receive the user’s certificate. From this certificate I can extract the user’s Public Key.

Now I want to verify that the signature against the signed text string and the user’s certificate and public key. I have tried with openssl_verify PHP function with no success.

I always receive an error:

error:0408D077:rsa routines:FIPS_RSA_VERIFY:wrong signature length

  • I have the certificate and it is OK;
  • I have the public key extracted from the certificate and it is also verified and OK;
  • I have the signature (BASE64 decoded);

Unfortunately I can’t verify the signature? I can’t provide a demo or sample because it is only in the local network at the moment.

  • 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-06-12T04:37:15+00:00Added an answer on June 12, 2026 at 4:37 am

    OK, finally I have found a workaround.

    1. I have a web page encoded in UTF-8 (this will be very important on some next steps);
    2. Generate the signature:
    • If the user uses Mozilla/Firefox/Chrome – the signature is generated using the window.crypto. For more information read this
    • If the user uses Internet Explorer – the signature is generated using the CAPICOM (Crypot Application Interface COM object). For more information read read MSDN
      Both – window.crypto and CAPICOM are not very well documented for web using (CAPICOM is not only for web!)
    1. The text string and the signature are being sent to the webserver by POST request.
    2. The sever (Linux, Apache and PHP) have to verify the signature.

    Now the problems:

    1. The openssl_verify() function of PHP is also not well documented and always returns zero – signature not valid.
    2. The CMD tool openssl also is not validating the signature.
    3. Because my web server requires SSL certificate authentication I wanted that the user signs the text string with the same certificate he is logged in.

    So what is the workaround:

    1. I found that CAPICOM is converting the signed string to UTF-16LE before signing it. Unfortunately the webbrowser sends the text string to the webserver encoded in UTF-8. It means you have to convert the string from UTF-8 to UTF-16LE before verifying the signature. But this is valid only if the signature was generated by CAPICOM.
    2. The openssl CMD tool is working proper now. The difference between the CMD tool and the PHP function are:
    • The signature and the source are sent to PHP function as strings. In case of using the CMD tool the signature and the source are sent as file paths. So if you are using the CMD instead of PHP function you have first to save the signature and the source as files. Remember to convert the encoding if needed.
    • The PHP function expects as a parameter to receive the public key of the signer. So before this you have to check if the certificate is issued by a trusted Certificate Authority (CA). Instead – the CMD tool expects as a parameter to receive a file which contains a list of root certificates of trusted Certificate Authorities. This means – you have to check the signer before verifying.
    1. It seems that under Firefox/Mozilla/Chrome browsers it is not possible to limit the user exactly which certificate to use for signing. But it is possible to limit the options. Of course this is not documented at all (or I didn’t find any proper information about this). So the signText() function expects a third parameter which must be the trusted Certificate Authority names. First I expected that this must be the CN of the issuer of the client’s certificate. But actually it is not. It must be all the issuer string separated with comas like: "C=Country,ST=State,L=Location,O=Organization,CN=CommonName,STREET=Address" Unfortunately this string is slightly different from the issuer string from openssl which looks like issuer=/streetAddress=Address/CN=CommonName/O=Organization/L=Location/ST=State/C=Country. If someone have a Firefox under Linux it will be very interesting to check if this string is formatted the same way. I don’t know how to separate more CA names in a single string.
    2. Under Internet Explorer, using CAPICOM it is possible to send only one certificate object to the signing object so it will not open the dialog to select a certificate from a list. You can find the proper certificate by comparing the root certificate fingerprint (A SHA1 hash of the BASE64 65 chr/line encoded certificate excluding the header and footer) and the serial number of the certificate. Just read the MSDN it is well documented.

    Now. What my source code looks like:

    1. If the signature was generated by CAPICOM of window.crypto (I receive an additional parameter from the webbrowser how the signature was generated) If CAPICOM is used I convert the source data like this: $_POST['source'] = iconv('UTF-8', 'UTF-16LE', $_POST['source'])
    2. I generate 2 temporary files. The names of the files can be generated using the PHP function uniqid(). The default temp directory can be found using the sys_get_temp_dir().
    3. The source file is saved exactly as received from the POST array. If the signature was generated by CAPICOM it must be converted to UTF-16LE.
    4. The signature comes from the web browser BASE64 encoded. Do not decode it. Just save it in a new file and add a special header and footer like this: "-----BEGIN PKCS7-----\n".$_POST['signature']."\n-----END PKSC7-----" Note that the header and footer must be on separate lines. The lines separator must be only \n (ASCII #10) not \r (ASCII #13) of \r\n (ASCII #13#10).
    5. You must have a file which contains all trusted CA root certificates. The format of this file must be as follows:
    • A header "—–BEGIN CERTIFICATE—–"
    • BASE64 encoded certificate
    • A footer "—–END CERTIFICATE—–"
    • empty line
    • If you have more than one trusted CA root – each certificate must start with a header and end with a footer string. All certificates are stored in a single file
    1. Run the CMD tool openssl using next parameters:
    • smime – to use the SMIME function of the CMD tool
    • -verify – to do a verification
    • -in filepath – the path to the signature file created in step 4
    • -inform PEM – the forat of the signature is BASE64 encoded file with header and footer
    • -binary – prevents translation of the source from binary to text
    • -content filepath – the path to the source file created in step 3
    • -CAfile filepath – the path to the trusted CA root certificates file created in step 5
      So the final command looks like this: openssl smime -verify -in file.pem -inform PEM -binary -content source.txt -CAfile root.pem
    1. Now call this from PHP using the shell_exec() function and read the output.
    • If the output string starts with Verification successful – the signature is OK
    • If the output string starts with Verification failure – the signature is not OK
    • If the output string is different – some error have occurred. The error description is stored in the output string.

    The above works for me. Unfortunately openssl, CAPICOM and window.crypto are very tricky and it is always possible that a problem occurs. Hope this will help somebody.

    Best Regards

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Javascript that opens another window and registers a click handler for all
I have a javascript that displays a generated text into a div: document.getElementById('phrase').innerHTML =
I have a Firefox component for PDF signing that I invoke via Javascript. The
I have javascript that turns dates in my view to a time string using
So, here is normal text: just your standard paragraph. I have javascript that will
I have JavaScript that is doing activity periodically. When the user is not looking
I have a javascript that returns a value whenever I choose an option from
I have some javascript that I am using for some audio on my website:
I have some javascript that goes out and fetches a javascript class on another
I have a javascript that calls a function each 1 minute. That function sends

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.