views:

291

answers:

0

So far I have found an example for Django that uses M2Crypto, but because M2Crypto is based on a C library, it cannot be run on GAE. Does anyone have a working code for creating an encrypted PayPal button dynamically in Google App Engine?

In a nutshell, I need to translate the following Ruby code into Python. It's taken from PayPal's Website Payments Standard toolkit for Ruby.

def self.encrypt_data(paypal_cert, my_business_cert, my_business_key,
                      my_business_key_password, myparams  )     
  paypal_cert      = OpenSSL::X509::Certificate.new(paypal_cert)     
  my_business_cert = OpenSSL::X509::Certificate.new(my_business_cert)      
  my_business_key  = OpenSSL::PKey::RSA.new(
    my_business_key,
    my_business_key_password)   
  info = ""
  myparams.each_pair {|key,value| info << "#{key}=#{value}\n"}    
  signedInfo       = OpenSSL::PKCS7::sign(
    my_business_cert,
    my_business_key,
    info,
    [],
    OpenSSL::PKCS7::BINARY)
  OpenSSL::PKCS7::encrypt(
    [paypal_cert],
    signedInfo.to_der,
    OpenSSL::Cipher::Cipher::new("DES3"),
    OpenSSL::PKCS7::BINARY)           
end