Decrypted TIF Image seems to not be identical... - WeOnlyDo Discussion board

Decrypted TIF Image seems to not be identical... (wodCrypt)

by Alex Loret de Mola, Saturday, December 31, 2005, 01:15 (4344 days ago)

Well met! A brief question for you...

Our software uses several large TIF images that must be encrypted and decrypted. I have noticed that, after using your reccommended encryption/decryption algorithm for files (except for the small change of using your AES 256 instead of standard AES), the TIF file after it comes out the other side of encryption and decryption has a fairly large amount of extra data in it (particularly at the end of the file). Though the file appears to be the same when viewed, I can no longer do size comparisons and/or hash integrity checks (MD5 or the like) which we need to check for corrupted files.

Is there any reason why this extra data is being added? The following is my code snippet:

* Encrypting a TIF image file:
mwodEncryptor.LicenseKey = (omitted for security)
mwodEncryptor.Type = AES256
mwodEncryptor.Optimized = False
mwodEncryptor.SecretKey = (omitted for security)
mfileIn.FileName = (path to unencrypted TIF image)
mfileOut.FileName = (path to where we want encrypted version to be)
Call mwodEncryptor.Encrypt(mfileIn, mfileOut)

* Decrypting the same file:
mwodEncryptor.LicenseKey = (omitted for security)
mwodEncryptor.Type = AES256
mwodEncryptor.Optimized = False
mwodEncryptor.SecretKey = (omitted for security)
mfileIn.FileName = (path to the encrypted file just created)
mfileOut.FileName = (path to where we want decrypted file to be)
Call mwodEncryptor.Decrypt(mfileIn, mfileOut)


If you run these two algorithms one after the other, you get a bunch of garbage appended to the end of the encrypted/decrypted image that renders my integrity checks useless. Any suggestions?

-Alex

Re: Decrypted TIF Image seems to not be identical.

by wodSupport, Saturday, December 31, 2005, 01:49 (4344 days ago) @ Alex Loret de Mola

Alex,

it's expected. Ciphers work on block of data, so when you encrypt, last chunk has to be aligned up to a 'BlockSize' of data, so few bytes are added. When you decrypt it, those bytes are also added to decrypted file. That's why you see garbage .

To get rid of it, use Optimized = True, or use PKCS7 padding.

Re: Decrypted TIF Image seems to not be identical.

by Alex Loret de Mola, Monday, January 02, 2006, 04:14 (4342 days ago) @ wodSupport

Alex,

it's expected. Ciphers work on block of data, so when you encrypt, last chunk has to be aligned up to a 'BlockSize' of data, so few bytes are added. When you decrypt it, those bytes are also added to decrypted file. That's why you see garbage .

To get rid of it, use Optimized = True, or use PKCS7 padding.

Ah, okay, I'll try it with the optimized setting then. Does that have any negative effect (as I remember reading somewhere in the docs that I shouldn't be setting it to Optimized)?

-Alex

Re: Decrypted TIF Image seems to not be identical.

by wodSupport, Monday, January 02, 2006, 09:13 (4342 days ago) @ Alex Loret de Mola

Alex,

only if you decrypt with something else than wodCrypt. If you encrypt and decrypt with wodCrypt, you're safe to use it.

Re: Decrypted TIF Image seems to not be identical.

by Alex Loret de Mola, Monday, January 02, 2006, 17:50 (4341 days ago) @ wodSupport

Alex,

only if you decrypt with something else than wodCrypt. If you encrypt and decrypt with wodCrypt, you're safe to use it.

OH! =) Okayo, I'll definately give that a shot when I go into work today. =)

-Alex

Re: Decrypted TIF Image seems to not be identical.

by Alex Loret de Mola, Monday, January 02, 2006, 19:45 (4341 days ago) @ Alex Loret de Mola

Alex,

only if you decrypt with something else than wodCrypt. If you encrypt and decrypt with wodCrypt, you're safe to use it.

OH! =) Okayo, I'll definately give that a shot when I go into work today. =)

-Alex

Hmm... I tried it (changed both encryption and decryption to use Optimized = True , and I got this error message:

Failed to decrypt data. Try setting optimized=FALSE.

Same code as above, but with mwodEncryptor.Optimized = True. Is there something I'm forgetting to do/something I'm doing wrong? Thanks for any info you can provide!

-Alex

Re: Decrypted TIF Image seems to not be identical.

by wodSupport, Monday, January 02, 2006, 19:47 (4341 days ago) @ Alex Loret de Mola

Alex,

can you create new VB project, paste your code inside, show how it fails to work, zip everything, and send to techsupport@weonlydo.com (together with TIF image) so we have exactly the same environment to test with. I'll try it here and see why it fails.

If you use Optimized = true on both sides - it just doesn't make sense to get that message, so I would like to try it out.

Re: Decrypted TIF Image seems to not be identical.

by Alex Loret de Mola, Monday, January 02, 2006, 20:05 (4341 days ago) @ wodSupport

Alex,

can you create new VB project, paste your code inside, show how it fails to work, zip everything, and send to techsupport@weonlydo.com (together with TIF image) so we have exactly the same environment to test with. I'll try it here and see why it fails.

If you use Optimized = true on both sides - it just doesn't make sense to get that message, so I would like to try it out.

Hmm, that's odd... I just made a new test project to show you with, and it's working fine there. I'm confused now as to what may be going on. Hmm... I'll keep looking, it could be something on my end.

-Alex

Re: Decrypted TIF Image seems to not be identical.

by Alex Loret de Mola, Monday, January 02, 2006, 20:37 (4341 days ago) @ Alex Loret de Mola

Alex,

can you create new VB project, paste your code inside, show how it fails to work, zip everything, and send to techsupport@weonlydo.com (together with TIF image) so we have exactly the same environment to test with. I'll try it here and see why it fails.

If you use Optimized = true on both sides - it just doesn't make sense to get that message, so I would like to try it out.

Hmm, that's odd... I just made a new test project to show you with, and it's working fine there. I'm confused now as to what may be going on. Hmm... I'll keep looking, it could be something on my end.

-Alex


Hmm, do the encrypt/decrypt methods return before a large file has completely finished encrypting/decrypting? I noticed the two events (Progress and Done), and so now I'm suspecting that perhaps the culprit is that I am not finished with the encryption process before I grab the file and attempt to decrypt it. In my test mentioned above, I had to manually enter information between encryption and decryption, which might explain why the test worked when my program (that has identical back end code) worked.

-Alex

Re: Decrypted TIF Image seems to not be identical.

by wodSupport, Monday, January 02, 2006, 20:39 (4341 days ago) @ Alex Loret de Mola

Alex,

methods will not return until they complete. Progress and Done events are just for information.

Re: Decrypted TIF Image seems to not be identical.

by Alex Loret de Mola, Monday, January 02, 2006, 21:52 (4341 days ago) @ wodSupport

Alex,

methods will not return until they complete. Progress and Done events are just for information.

Hmm, they must be returning prematurely though for the event to be picked up by VB though right? I've never completely understood the internal workings of VB's event system. =(

I went and dusted off my help file (I finally found it! I put it in a very inconvenient place on my computer =( ) and found the FireEvents property. Setting it to false, I found that the file would encrypt/decrypt fully by the time the method returns and thus my program is working again. It may have just been coincidence, or I may have fixed something without realizing it, but now it's encrypting and decrypting fully and properly.

I'll leave it like this I think: the program shouldn't need the notification events anyways. Thanks for the help, especially with the Optimize idea... I'd forgotten completely about that. =)

-Alex