'Use your key thing to encrypt things.'

def _encrypt(self):

    from M2Crypto import BIO, SMIME, X509
    CERT = settings.PAYPAL_PRIVATE_CERT
    PUB_CERT = settings.PAYPAL_PUBLIC_CERT
    PAYPAL_CERT = settings.PAYPAL_CERT
    CERT_ID = settings.PAYPAL_CERT_ID
    plaintext = ('cert_id=%s\n' % CERT_ID)
    for (name, field) in self.fields.items():
        value = None
        if (name in self.initial):
            value = self.initial[name]
        elif (field.initial is not None):
            value = field.initial
        if (value is not None):
            if (name == 'return_url'):
                name = 'return'
            plaintext += (u'%s=%s\n' % (name, value))
    plaintext = plaintext.encode('utf-8')
    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()
