Can I add 2 encrypted strings together and decrypt them?
I have 2 methods to generate 2 different data and need to save them in one encrypted file.
Can I achieve this by adding encrypted stringA + encrypted st开发者_如何学PythonringB, then decrypt them later?
Or
I have to encrpt stringA -> save as file -> read the file & decrypt to stringA -> stringA + stringB -> encrypt ?
NB, I am using Rijndael(AES) and someone suggested using customerized stream, will it work?
Any thoughts? Many thanks~
If you're using ECB (electronic code book), then it should be possible (assuming they use the same encryption key), because each block is decrypted independent of other blocks. If you're using CBC (cipher block chaining) this will not work because each block is encrypted using data from the previous block. However, using ECB is way less secure than CBC.
If you encrypt each separately, and know the length of each block of encrypted text, you can decrypt them later individually.
Something like this format would probably work:
Message1Length
Message1Content
Message2Content
Read the Message1Length number of bytes into the message and store it as encryptedMessage1 or something. Then read from that point to the End of File and store it as encryptedMessage2. Then decrypt them both individually.
It depends on which encryption algorithm you use. For block ciphers in ECB mode, it would work - but ECB mode is considered very insecure exactly because of this (it makes certain kinds of attack on the cipher very easy).
精彩评论