让 django-paypal 与 pycrypto 一起使用?

发布于 2024-08-05 22:07:29 字数 767 浏览 2 评论 0原文

我想在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我不咬妳我踢妳 2024-08-12 22:07:29

我能够构建它。为了实现这一目标,您需要执行以下操作:

cat >> ~/.pydistutils.cfg << EOF
[build_ext]
include_dirs=/usr/include/openssl
EOF
easy_install-2.5 --install-dir=$HOME/lib/python2.5 --script-dir=$HOME/bin m2crypto

I was able to get it to build. Here is all you need to do to make it happen:

cat >> ~/.pydistutils.cfg << EOF
[build_ext]
include_dirs=/usr/include/openssl
EOF
easy_install-2.5 --install-dir=$HOME/lib/python2.5 --script-dir=$HOME/bin m2crypto
逆光飞翔i 2024-08-12 22:07:29

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.

ゞ花落谁相伴 2024-08-12 22:07:29

您可以在本地设置虚拟机并复制足够的 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文