我发现这篇文章Create Google Chrome Crx file with PHP to create a .crx file vith my ZIP archive。但是当我尝试运行它时,我得到了 $signtrue = 0 的长度,但我不知道为什么......我的 .pem 文件已找到且有效,还有我的 .pub 密钥文件,但它仍然返回给我签名中的零长度...
$fp = fopen("/public_html/apps/chrome/nsii.pem", "r");
$priv_key = fread($fp, filesize($fp));
fclose($fp);
$pkeyid = openssl_get_privatekey($priv_key);
openssl_sign(file_get_contents("$name.zip"), $signature, $pkeyid, 'sha1');
openssl_free_key($pk);
# decode the public key
$key = base64_decode(file_get_contents('extension_public_key.pub'));
$fh = fopen("$name.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("$name.zip")); // package contents, zipped
fclose($fh);
更新:
原代码如下:
<?php
# make a SHA1 signature using our private key
$pk = openssl_pkey_get_private(file_get_contents('/public_html/apps/chrome/nsii.pem'));
openssl_sign(file_get_contents('/public_html/apps/chrome/extGoogle.zip'), $signature, $pk, 'sha1');
openssl_free_key($pk);
# decode the public key
$key = base64_decode(file_get_contents('/public_html/apps/chrome/extension_public_key.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($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('/public_html/apps/chrome/extGoogle.zip')); // package contents, zipped
fclose($fh);
似乎也不能正常工作...问题是为什么?...如果我使用 CLI 编译它,一切正常...