php chrome.crx,从PHP生成Chrome .crx

你使用的openssl_pkey_export错了,你还没有删除

-----BEGIN PUBLIC KEY-----

...

-----END PUBLIC KEY-----

解码之前从公钥字符串.我通过查看公钥和签名的长度来解决这个问题.第一个应该是161,第二个应该是128个字节长(source):

A2 00 00 00 # 162 -- length of public key in bytes

80 00 00 00 # 128 -- length of signature in bytes

这是固定代码(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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值