我希望能够用PHP生成一个crx文件。
crx文件是一个带有附加头的zip文件,我不知道如何创建这个头文件。如果我使用预先生成的pem文件,我可以创建一个crx文件,但这会导致所有的crx文件都具有相同的扩展名id,这是不好的。这是我到目前为止所得到的链接……
http://valorsolo.com/index.php?page=Viewing%20Message&id=1472&pagenum=2#1500
在Python中已经做到了这一点,这里有一篇很好的博客文章,介绍了更详细的细节……
http://blog.roomanna.com/12-12-2010/packaging-chrome-extensions
这里有一些关于这个主题的其他代码的链接……
http://code.google.com/chrome/extensions/crx.html
http://code.google.com/p/crx-packaging/source/browse/trunk/packer.py
https://github.com/bellbind/crxmake-python/blob/master/crxmake.py
http://www.curetheitch.com/projects/buildcrx/
发布于 2011-04-08 03:17:03
这个ruby code很有帮助。
您的公钥必须是DER格式,不幸的是,据我所知,PHP的OpenSSL扩展不能这样做。我必须在命令行从我的私钥生成它:
openssl rsa -pubout -outform DER < extension_private_key.pem > extension_public_key.pubPHP :有一个 der2pem()函数available here,感谢tutuDajuju指出它。
完成后,构建.crx文件就非常简单了:
# make a SHA1 signature using our private key
$pk = openssl_pkey_get_private(file_get_contents('extension_private_key.pem'));
openssl_sign(file_get_contents('extension.zip'), $signature, $pk, 'sha1');
openssl_free_key($pk);
# decode the public key
$key = base64_decode(file_get_contents('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('extension.zip')); // package contents, zipped
fclose($fh);发布于 2011-02-17 11:33:07
文档页面http://code.google.com/chrome/extensions/crx.html中详细介绍了CRX格式。
在该文件的末尾有Ruby和Bash的示例。遵循您的语言(PHP)中的格式。
发布于 2013-11-16 19:44:20
您可以使用有效的PHP解决方案:https://github.com/andyps/crxbuild有一个PHP类,您可以将其包含在项目和命令行脚本中。
https://stackoverflow.com/questions/5013263
复制相似问题