login about faq

I am trying to use this API from Python 2.7, but I am having trouble. The documentation shows:

# data is a CkByteData
# outData is a CkByteData (output)
status = crypt2.EncryptBytes(data, outData);
but Python does not allow parameters (outdata) to receive results.

I notice that some of the API's have lower-case equivalents (i.e., encryptBytes) that return the output instead of the status. If I try that, I get an exception: "AttributeError: encryptBytes"

Ideally, I'd like to pass bytes (the Python type) in, and receive bytes back so as to eliminate conversions, as throughput is an issue. Ditto for decrypt.

asked Oct 11 '15 at 18:24

chilkat's gravatar image

chilkat ♦♦

Methods that return binary bytes do so by depositing the bytes in the output-only CkByteData object that is passed in the last argument. This is an object that would first be instantiated by the Python script, and then passed to the method. The empty CkByteData is passed in the last argument, and it is filled with the result bytes. The success/failure of any method returning bytes in this way is the boolean value returned by the method: True(success) / False(failure).

For example:

import chilkat

crypt = chilkat.CkCrypt2()


# Load something from a file. # Create a CkByteData object to hold the bytes. inByteObj = chilkat.CkByteData() success = inByteObj.loadFile("hamlet.xml")

# Encrypt bytes # Create a CkByteData object to hold the encrypted bytes. encByteObj = chilkat.CkByteData() success = crypt.EncryptBytes(inByteObj, encByteObj) # save the encrypted bytes to a file encByteObj.saveFile("hamletEncrypted.enc")

# grab a pointer to the bytes for Python to access. # this is not copying the bytes -- it's just returning a pointer to the bytes. p = encByteObj.getBytes() f = open('h.enc', 'wb') f.write(p) f.close()

# Create a CkByteData object to hold the decrypted bytes: decByteObj = chilkat.CkByteData()

success = crypt.DecryptBytes(encByteObj,decByteObj) # save the decrypted bytes to a file. decByteObj.saveFile("hamletDecrypted.xml")


answered Oct 11 '15 at 18:34

chilkat's gravatar image

chilkat ♦♦

edited Oct 11 '15 at 18:34

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Oct 11 '15 at 18:24

Seen: 516 times

Last updated: Oct 11 '15 at 18:34

powered by OSQA