让 django-paypal 与 pycrypto 一起使用?
我想在 django-paypal 中使用按钮加密,但它需要 M2Crypto,而 M2Crypto 不会构建在 webfaction 服务器上。 Webfaction 的技术支持告诉我,系统上已经安装了 pycrypto,但我太笨了,无法从 M2Crypto 转换为 pycrypto。
谁能告诉我如何将以下内容转换为与 pycrypto 一起使用(如果可能)?这只是显示加密的一个小片段,如果需要,我可以发布整个函数。
s = SMIME.SMIME()
s.load_key_bio(BIO.openfile(CERT), BIO.openfile(PUB_CERT))
p7 = s.sign(BIO.MemoryBuffer(plaintext), flags=SMIME.PKCS7_BINARY)
x509 = X509.load_cert_bio(BIO.openfile(settings.PAYPAL_CERT))
sk = X509.X509_Stack()
sk.push(x509)
s.set_x509_stack(sk)
s.set_cipher(SMIME.Cipher('des_ede3_cbc'))
tmp = BIO.MemoryBuffer()
p7.write_der(tmp)
p7 = s.encrypt(tmp, flags=SMIME.PKCS7_BINARY)
out = BIO.MemoryBuffer()
p7.write(out)
return out.read()
I would like to use the button encryption in django-paypal, but it requires M2Crypto which will not build on webfaction servers. Tech support at Webfaction told me that pycrypto is already installed on the system, but I am too dumb to translate from M2Crypto to pycrypto.
Can anyone tell me how to convert the following to work with pycrypto (if possible)? This is just a small snip showing he encryption, I can post the entire function if needed.
s = SMIME.SMIME()
s.load_key_bio(BIO.openfile(CERT), BIO.openfile(PUB_CERT))
p7 = s.sign(BIO.MemoryBuffer(plaintext), flags=SMIME.PKCS7_BINARY)
x509 = X509.load_cert_bio(BIO.openfile(settings.PAYPAL_CERT))
sk = X509.X509_Stack()
sk.push(x509)
s.set_x509_stack(sk)
s.set_cipher(SMIME.Cipher('des_ede3_cbc'))
tmp = BIO.MemoryBuffer()
p7.write_der(tmp)
p7 = s.encrypt(tmp, flags=SMIME.PKCS7_BINARY)
out = BIO.MemoryBuffer()
p7.write(out)
return out.read()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我能够构建它。为了实现这一目标,您需要执行以下操作:
I was able to get it to build. Here is all you need to do to make it happen:
pycrypto 非常不完整。它不支持您需要的填充方案和格式。添加对这些格式的支持并非易事,并且需要大量时间。
pycrypto is very incomplete. It does not support the padding schemes and formats that you need. Adding support for those formats is not trivial and will require a lot of time.
您可以在本地设置虚拟机并复制足够的 webfaction 服务器环境来自行构建。然后上传到你的pythonpath上的某个地方
You may be able to set up a virtual machine locally and duplicate enough of the webfaction server environment to build it yourself. Then upload to somewhere on your pythonpath