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