phpseclibを使用して PHP で crx ファイルを生成しています。crx を Chrome にインストールしようとすると、次のエラーが表示されます。
Package is invalid: 'CRX_SIGNATURE_VERIFICATION_INITIALIZATION_FAILED'
これが私のコードです:
<?php
//Include phpseclib files
include('File/X509.php');
include('Crypt/RSA.php');
//RSA Handler
$rsa = new Crypt_RSA();
//Create key pair
$keyPair = $rsa->createKey();
//Get the keys
$privKey = $keyPair[ "privatekey" ];
$pubKey = $keyPair[ "publickey" ];
//The Zip file contents
$zipContents = file_get_contents( "helloworld.zip" );
//Load the private key into the handler
$rsa->loadKey( $privKey );
//Sign the content (default is SHA1)
$signature = $rsa->sign( $zipContents ) ;
/* Tried this, but it also did not work */
//Convert to openSSH and remove the leading/trailing "comments": "ssh-rsa ", " phpseclib-generated-key"
//$rsa->loadKey( $pubKey );
//$rsa->setPublicKey();
//$pubKey = $rsa->getPublicKey( CRYPT_RSA_PUBLIC_FORMAT_OPENSSH );
//$pubKey = substr( $pubKey, 8, strlen( $pubKey ) - 32 );
//Encode public key in Base64 and remove the "-----BEGIN PUBLIC KEY-----\r\n" and "\r\n-----END PUBLIC KEY-----" (to put in .crx)
$base64Key = base64_decode( substr( $pubKey, 28, strlen( $pubKey ) - 54 ) );
//Create the crx (wb = write in binary mode)
$crxFile = fopen( "helloworld.crx", "wb" );
//Add crx "magic" marker, format version
fwrite( $crxFile, "Cr24" );
fwrite( $crxFile, pack( "V", 2 ) );
//Write public key and signature length
fwrite( $crxFile, pack( "V", strlen( $base64Key ) ) );
fwrite( $crxFile, pack( "V", strlen( $signature ) ) );
//Write public key (base64 encoded) and signature
fwrite( $crxFile, $base64Key );
fwrite( $crxFile, $signature );
//Write the zip file contents
fwrite( $crxFile, $zipContents );
fclose( $crxFile );
?>
私は何を間違っていますか?キーの形式と署名に関係していると思いますか?