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 9000545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:19:29+00:00 2026-06-16T00:19:29+00:00

I want to generate a Chrome extension (Chrome theme) from PHP. My PHP script

  • 0

I want to generate a Chrome extension (Chrome theme) from PHP. My PHP script generates a zip file (download.zip). To convert it to a .crx package, it needs to add headers, including a public key and a signature.

I saw this answer, but you need a .pem file that generates a .pub file. I’m on a shared hosting so exec() won’t work (to convert a .pem to a .pub). There is no need to have a .pem file, it only has to use it once downloading (no updating needed).

Then I saw this comment that explains you can generate the private and public keys. Combining the two scripts won’t work (see code).

How can I generate a keypair and use it to sign a chrome .crx package with PHP?

This code fails (CRX_SIGNATURE_VERIFICATION_INITALIZATION_FAILED):

// Create the keypair
$res=openssl_pkey_new();

// Get private key
openssl_pkey_export($res, $pk);

// Get public key
$key=openssl_pkey_get_details($res);
$key=$key["key"];

# make a SHA1 signature using our private key
openssl_sign(file_get_contents('download.zip'), $signature, $pk, 'sha1');

# decode the public key
$key = base64_decode($key);

# .crx package format:
#
#   magic number               char(4)
#   crx format ver             byte(4)
#   pub key lenth              byte(4)
#   signature length           byte(4)
#   public key                 string
#   signature                  string
#   package contents, zipped   string
#
# see http://code.google.com/chrome/extensions/crx.html
#
$fh = fopen('extension.crx', 'wb');
fwrite($fh, 'Cr24');                             // extension file magic number
fwrite($fh, pack('V', 2));                       // crx format version
fwrite($fh, pack('V', strlen($key)));            // public key length
fwrite($fh, pack('V', strlen($signature)));      // signature length
fwrite($fh, $key);                               // public key
fwrite($fh, $signature);                         // signature
fwrite($fh, file_get_contents('download.zip')); // package contents, zipped
fclose($fh);
  • 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-16T00:19:29+00:00Added an answer on June 16, 2026 at 12:19 am

    You were using openssl_pkey_export wrong and you haven’t removed

    -----BEGIN PUBLIC KEY-----
    ...
    -----END PUBLIC KEY-----
    

    from public key string before decoding it. I figured this out by looking at length of public key and signature. First one should be 161 and second one should be 128 bytes long (source):

    A2 00 00 00   # 162 -- length of public key in bytes
    80 00 00 00   # 128 -- length of signature in bytes
    

    Here is the fixed code (PHP 5.4):

    $pk=file_get_contents('pk.pem');
    
    $priv = openssl_pkey_get_private($pk);
    $pub = openssl_pkey_get_details($priv)['key'];
    
    # make a SHA1 signature using our private key
    openssl_sign(file_get_contents('download.zip'), $signature, $priv, OPENSSL_ALGO_SHA1);
    
    # geting rid of -----BEGIN/END PUBLIC KEY-----
    # you can probably do it better using preg_match_all / explode(PHP_EOL, $pub) etc.
    $pub = trim(explode('-----',$pub)[2]);
    
    # decode the public key
    $pub = base64_decode($pub);
    
    # .crx package format:
    #
    #   magic number               char(4)
    #   crx format ver             byte(4)
    #   pub key lenth              byte(4)
    #   signature length           byte(4)
    #   public key                 string
    #   signature                  string
    #   package contents, zipped   string
    #
    # see http://code.google.com/chrome/extensions/crx.html
    #
    $fh = fopen('extension.crx', 'wb');
    fwrite($fh, 'Cr24');                             // extension file magic number
    fwrite($fh, pack('V', 2));                       // crx format version
    fwrite($fh, pack('V', strlen($pub)));            // public key length
    fwrite($fh, pack('V', strlen($signature)));      // signature length
    fwrite($fh, $pub);                               // public key
    fwrite($fh, $signature);                         // signature
    fwrite($fh, file_get_contents('download.zip')); // package contents, zipped
    fclose($fh);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to generate a bar graph from from a csv file my data
I want to generate an HTML table from a couple specified parameters. Specifically, the
I want to generate a LaTeX document from Objective-C and compile it with pdfLatex
I'm developing a Google Chrome extension and I want to retrieve Google+ notifications count
I generate a file server side and I want the client to automatically open
I want generate static pages from database. What is a better suggestion that a
I use XSLT to generate an HTML table using info from an XML file.
Let's say I have a class of 30 students and want generate every possible
I want to generate a list of files where the name consists of ${filename}.${date}
I want to generate a random timestamp and add a random increment to it

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.