首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过PHP生成crx文件失败,并显示:"Package is invalid: CRX_SIGNATURE_VERIFICATION_INITIALIZATION_FAILED“

通过PHP生成crx文件失败,并显示:"Package is invalid: CRX_SIGNATURE_VERIFICATION_INITIALIZATION_FAILED“
EN

Stack Overflow用户
提问于 2013-05-24 04:55:32
回答 1查看 301关注 0票数 0

我使用phpseclib在PHP中生成一个crx文件。当我尝试将crx安装到Chrome中时,我收到以下错误:

代码语言:javascript
复制
Package is invalid: 'CRX_SIGNATURE_VERIFICATION_INITIALIZATION_FAILED'

下面是我的代码:

代码语言:javascript
复制
<?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 );
?>

我做错了什么?我猜这跟钥匙的格式和签名有关吧?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-24 14:29:35

我找到答案了!签名使用的是CRYPT_RSA_SIGNATURE_PSS,显然只适用于PKCS1

代码语言:javascript
复制
$rsa->setSignatureMode( CRYPT_RSA_SIGNATURE_PKCS1 );

在签名创建代码之前。因此,签名代码现在如下所示:

代码语言:javascript
复制
//Load the private key into the handler
$rsa->loadKey( $privKey );

//Sign the content (default is SHA1)
$rsa->setSignatureMode( CRYPT_RSA_SIGNATURE_PKCS1 ); /* <-- This is required */
$signature = $rsa->sign( $zipContents ) ;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16723725

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档