Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine 使用Java生成Chrome打包的App.crx头_Google App Engine_Rsa_X509_Google Chrome App - Fatal编程技术网

Google app engine 使用Java生成Chrome打包的App.crx头

Google app engine 使用Java生成Chrome打包的App.crx头,google-app-engine,rsa,x509,google-chrome-app,Google App Engine,Rsa,X509,Google Chrome App,我试图用Java构建头文件,但运气不好。 (这是规范:) 有什么想法吗 受保护的void geneateCrxHeader(OutputStream-ins,byte[]zipArchive)抛出NoSuchAlgorithmException、NoSuchProviderException、IOException、InvalidKeyException、SignatureException{ KeyPairGenerator keyGen=KeyPairGenerator.getInstanc

我试图用Java构建头文件,但运气不好。 (这是规范:) 有什么想法吗

受保护的void geneateCrxHeader(OutputStream-ins,byte[]zipArchive)抛出NoSuchAlgorithmException、NoSuchProviderException、IOException、InvalidKeyException、SignatureException{
KeyPairGenerator keyGen=KeyPairGenerator.getInstance(“RSA”);
SecureRandom=SecureRandom.getInstance(“SHA1PRNG”、“SUN”);
keyGen.initialize(1024,随机);
KeyPair=keyGen.generateKeyPair();
byte[]key=pair.getPublic().getEncoded();
Signature instance=Signature.getInstance(“SHA1withRSA”);
initSign(pair.getPrivate());
实例更新(zipArchive);
byte[]hash=instance.sign();
字节[]magic={0x43,0x72,0x32,0x34,0x02,0x00,0x00,0x00,0x01,0x0E,0x0B,0x00,0x00,0x00,0x08,0x00};
写作(魔术);
ins.write(键);
ins.write(哈希);
}
我得到了CRX\u过大的\u密钥\u或\u签名。。 我一定是用错钥匙了

在文件中,他们确实说: ”。作者的RSA公钥的内容,格式为X509 SubjectPublicKeyInfo块。。" 我不知道这是不是我做得不对…


p、 s Java crypto对我来说是一个新的前沿,所以如果我做了一些完全愚蠢的事情,请不要笑。

这里有一些代码是我编写的,没有测试过的,说明了只生成标题。我完全基于阅读规范

导入java.nio.ByteBuffer;
导入java.nio.ByteOrder;
导入java.security.KeyPair;
导入java.security.KeyPairGenerator;
导入java.security.SecureRandom;
导入java.security.Signature;
公共静态字节[]GenerateRxHeader(字节[]扩展内容)引发异常{
KeyPairGenerator keyGen=KeyPairGenerator.getInstance(“RSA”);
SecureRandom=新的SecureRandom();
keyGen.initialize(1024,随机);
KeyPair=keyGen.generateKeyPair();
Signature Signature=Signature.getInstance(“SHA1withRSA”);
initSign(pair.getPrivate());
更新(扩展内容);
byte[]signature=signInstance.sign();
字节[]subjectPublicKeyInfo=pair.getPublic().getEncoded();
最终int headerLength=4+4+4+4+subjectPublicKeyInfo.length+signature.length;
ByteBuffer headerBuf=ByteBuffer.allocate(headerLength);
headerBuf.order(字节顺序、小字节);
headerBuf.put(新字节[]{0x43,0x72,0x32,0x34});//幻数
headerBuf.putInt(2);//版本
headerBuf.putInt(subjectPublicKeyInfo.length);//公钥长度
headerBuf.putInt(signature.length);//签名长度
headerBuf.put(subjectPublicKeyInfo);
校长签字;
最后一个字节[]头=headerBuf.array();
返回头;
}

您的公钥长度和签名长度似乎是硬编码的。您从何处获得用于公钥长度的字节
0x00,0x01,0x0E,0x0B
?我尝试表示491字节长度。但我更喜欢下面的解决方案。不知道您可以执行“headerBuf.order”(ByteOrder.LITTLE\ENDIAN);“现在我知道了:)def.今天学到了一些东西。我将在一段真正的代码中尝试一下。就是这样!!!!!!!谢谢你。slopy byte[]是我的工作。使用ByteBuffer是这里的关键。我确信我使用了错误的加密算法。