I want to encrypt and decrypt file in Iphone using AESEncryption. It works good for NSData. But if i take Data in chunks my file gets currpt. How do i do this. I am able to encrypt and decrypt data using commoncrypto library. But problem occours when i try to read data in chunks.
Thank you in advance. Please Help. I need to开发者_StackOverflow implement this asap.
AES encryption is block-based; it works on blocks of 16 bytes of data at a time. If you jump into encrypted data at an arbitrary point that in not on a block boundary then you will get corrupt data when you decrypt.
What you need to do is calculate the start and end block boundaries that encompass the region you want to decrypt, do the decryption, then trim the start and end of the extraneous bytes. Alternatively, just make sure that you are always working in multiples of 16 bytes and limit your data access to block boundaries.
精彩评论