This ruby code was helpful。
你的公钥必须是DER格式,不幸的是PHP的OpenSSL扩展不能这样做,据我所知。我不得不在命令行中从我的私人密钥生成它:
openssl rsa -pubout -outform DER <extension_private_key.pem> extension_public_key.pub
UPDATE:有一个PHP 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);
如果我能做到这一点,我不会寻求帮助;) 但是,感谢您提出这个链接,我忘了那个......我已经阅读了它(很多次),它只是一个超越我。 – PAEz 2011-02-17 07:02:59