login about faq

Hello, How can i get boolean value in C++ for CkEncryptFile and get if file is already encrypted? Thanks.

asked Jun 07 at 14:08

BAILANDO's gravatar image


I don't think you can - when a file is encrypted it takes on the appearance of random (or near random) bytes. That said, you could create your own file format that has either a leading or trailing identifier that identifies it as one of your encrypted files, and then detect that identifier to determine if the file is already encrypted before encrypting it again. Before decrypting, you should strip the identifier or you will get incorrect results.


Unencrypted file = THISISAFILE

Encrypted file = aj09243hijwbg

Encrypted file with header = MYENCRYPTEDFORMAT_aj09243hijwbg

User attempts to encrypt a file - if you detect MYENCRYPTEDFORMAT_ at the start of the file, then refuse to encrypt.

User attempts to decrypt a file - if you detect MYENCRYPTEDFORMAT_ at the start of the file, strip it then decrypt the remaining bytes. If you don't detect the header, then alert the user that the file is no encrypted and refuse to decrypt.


answered Jun 07 at 16:59

jpbro's gravatar image

jpbro ♦

i think you mean same think what i made, i made encrypted file (encrypt filename+ext) and add ext .locked. when i decrypting, then i decrypt only string without .locked and make if where i list files only with locked ext and this works :) thanks.

but one last question, how can i check or if its possible, then how can i check when user enter incorrect password for decryption. for example i encrypt file with

crypto->CryptAlgorithm = "aes"; crypto->CipherMode = "ecb"; crypto->EncodingMode = "hex"; crypto->KeyLength = 256; crypto->SetSecretKeyViaPassword("heslo");

and user decrypt with for example crypto->CryptAlgorithm = "aes"; crypto->CipherMode = "ecb"; crypto->EncodingMode = "hex"; crypto->KeyLength = 256; crypto->SetSecretKeyViaPassword("hESlo");

its possible? thanks :)


answered Jun 07 at 17:07

BAILANDO's gravatar image


Example: Before encrypt: http://prntscr.com/bdm75v After encrypt: http://prntscr.com/bdm7ks After decrypt: http://prntscr.com/bdm7tp Programs look like: http://prntscr.com/bdm84v

(Jun 07 at 17:16) BAILANDO

Not sure if it is possible to check for an incorrect password unless you encrypt some ind of identifier in your data then verify it's existing after decrypting - if found, you would then need to strip it from the decrypted data to get the exact original file. If not found, then something went wrong (e.g. wrong password) so you can just delete the bad decrypted file and alert the user.

Other possibilities might be HMAC or GCM, but I've never used these so you'd need to do some searching/testing. Looks like Chilkat supports both though.

(Jun 08 at 11:05) jpbro ♦

Lastly, I've seen a lot of advice against using ECB mode - seems CBC is more secure?

(Jun 08 at 11:05) jpbro ♦

Go to this URL: https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation

Then scroll down to the picture of the Linux penguin. You'll see the pic encrypted w/ ECB mode and also with another mode (likely CBC). You'll understand the difference.. (With ECB, each output block is only dependent on the input block. The same input block produces the same output block. With CBC or other modes, the previous input alters the current output block.

(Jun 08 at 17:37) chilkat ♦♦

Yikes to ECB!

(Jun 08 at 19:56) jpbro ♦
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: Jun 07 at 14:08

Seen: 259 times

Last updated: Jun 08 at 19:56

powered by OSQA