C# 如何用C代码替换openSSL调用?
今天我在为chrome制作新的主题创建者时遇到了一个问题。你可能知道,Chrome使用了一种新的文件格式,叫做CRX,来管理它的插件和主题。这是一个基本的zip文件,但有点修改: Cr24+derkey+signature+zipFile 问题来了。只有两个CRX创建者,用Ruby或Python编写。我不太清楚这两种语言在Python方面都有一些基本的经验,但主要是PyS60,所以我想请您帮助我将这个Python应用程序转换为不依赖于外部程序的C代码 此外,以下是crxmake.py的来源:C# 如何用C代码替换openSSL调用?,c#,python,openssl,C#,Python,Openssl,今天我在为chrome制作新的主题创建者时遇到了一个问题。你可能知道,Chrome使用了一种新的文件格式,叫做CRX,来管理它的插件和主题。这是一个基本的zip文件,但有点修改: Cr24+derkey+signature+zipFile 问题来了。只有两个CRX创建者,用Ruby或Python编写。我不太清楚这两种语言在Python方面都有一些基本的经验,但主要是PyS60,所以我想请您帮助我将这个Python应用程序转换为不依赖于外部程序的C代码 此外,以下是crxmake.py的来源:
#!/usr/bin/python
# Cribbed from http://github.com/Constellation/crxmake/blob/master/lib/crxmake.rb
# and http://src.chromium.org/viewvc/chrome/trunk/src/chrome/tools/extensions/chromium_extension.py?revision=14872&content-type=text/plain&pathrev=14872
# from: http://grack.com/blog/2009/11/09/packing-chrome-extensions-in-python/
import sys
from array import *
from subprocess import *
import os
import tempfile
def main(argv):
arg0,dir,key,output = argv
# zip up the directory
input = dir + ".zip"
if not os.path.exists(input):
os.system("cd %(dir)s; zip -r ../%(input)s . -x '.svn/*'" % locals())
else:
print "'%s' already exists using it" % input
# Sign the zip file with the private key in PEM format
signature = Popen(["openssl", "sha1", "-sign", key, input], stdout=PIPE).stdout.read();
# Convert the PEM key to DER (and extract the public form) for inclusion in the CRX header
derkey = Popen(["openssl", "rsa", "-pubout", "-inform", "PEM", "-outform", "DER", "-in", key], stdout=PIPE).stdout.read();
out=open(output, "wb");
out.write("Cr24") # Extension file magic number
header = array("l");
header.append(2); # Version 2
header.append(len(derkey));
header.append(len(signature));
header.tofile(out);
out.write(derkey)
out.write(signature)
out.write(open(input).read())
os.unlink(input)
print "Done."
if __name__ == '__main__':
main(sys.argv)
请帮我一下好吗?对于Linux,有多种实用程序可以执行此操作—包括一个用于bash的实用程序—但听起来您希望从您的C评论中获得一些windows猜测功能 我曾试图包括所有链接,但我是新的stackoverflow用户,只能发布1个链接 无论如何,所有这些都可以在windows中工作,但是它们需要语言解释器和OpenSSL的设置-所以我花了几个小时,用C编写了一个在windows或linux上运行的版本,但我不确定为什么要在linux中使用它 它有OpenSSL静态链接,因此不需要解释器或库 可在以下位置找到存储库: 应该注意的是,我不使用windows—这是在Linux上编写的,win32二进制文件是在Linux以及OpenSSL库上交叉编译的—我在windows中测试过—但没有广泛使用。如果您有问题,请不要在此请求支持;我不会回应。使用上面链接的问题页面 此外,我不会将其转换为C-我看不出有任何理由将C用于这样一个简单的实用程序,这只会使对其他软件的需求永久化,以便它在其他平台上有用