Archived Forum Post

Index of archived forum posts


How to encrypt a stream or a file with chilkat?

Sep 30 '14 at 08:24

Hello I try to use Delphi non activeX dll.

my actually task is to encrypt a binary document.

function TOmEncrypterPdf.DoEncrypt(data: RawUTF8; publickey: RawUTF8): Boolean;
  encryptedStr: PWideChar;
  key, str: PWideChar;
  bytes: HCkByteData;
  s: String;
  key := PWideChar(WideString(publickey));
  str := PWideChar(WideString(data));
  bytes := CkByteData_Create();
  CkCrypt2_StringToBytes(cryptor, str, PWideChar('utf-8'), bytes);
  CkRsa_ImportPublicKey(cryptor, key);
  encryptedStr := CkRsa__encryptBytesENC(cryptor, bytes, False);
  msg.Details.Document := encryptedStr;

I try to get bytes array from my string but get AccessViolation exception:

CkCrypt2_StringToBytes(cryptor, str, PWideChar('utf-8'), bytes);

How to allocate bytes to write encrypted text into ?