I have to encrypt the output file in A application, then decrypt it in B application, but I found there are some limitations with MS encryption, if I encrypt a 1000 bytes buffer and then want to decrypt start for different position with different size in B application, the return values are error. Is there any encryption can meet my requirement? Thanks. Here is my sample codes:
clTemp.EncryptDataDirectly(buffer, 1000); clTemp.DecryptDataDirectly(buffer + 1, 500);
Disclaimer: I don’t know this Windows API for encryption. So this is just a general outline of the problem. Use your common sense and the documentation to find out more.
There a two possibilities:
Stream-ciphers. They encrypt one byte (or maybe even bit) at the time and you have to start at the beginning of the encrypted stream to decrypt it properly. Some ciphers have synchronization abilities that help you recover after some small error in the transmission.
Block-ciphers. They encrypt fixed sized blocks, 64 or 128 bit are popular block sizes. But they can use different modes for encryption. ECB for example encrypts every block by itself. you could jump into the middle of your file, grab a block and decrypt it. But it leaves you open to known plaintext attacks where an attacker knows some encrypted text and tries to find the key you used. CBC or some other mode with feedback is more secure, but in this case you need again to start decrypting at the beginning of your encrypted file.
Here are some relevant Wikipedia articles: