Reputation: 46760
I'm using TripleDESCryptoServiceProvider
to encrypt data and one thing I notice is that when I decrypt data using it, the data sometimes ends with a series of '\0'
characters. So, if I encrypt "Sachin"
and then decrypt the encrypted version of this I get back "Sachin\0\0"
. Is this a problem?
Upvotes: 2
Views: 281
Reputation: 15693
Probably, your encryption method is adding some padding, zero padding in this case. Your decryption method is not expecting padding, so it just decrypts it as if it was part of the original plaintext.
DES is a block cypher, and it can only work with data in 64 bit (8 byte) blocks. Any plaintext is padded to the next block boundary.
Zero padding is not good, because you get into problems if the plain text ends in a zero byte (like a C-style string). Change your encryption method to add PKCS#5 padding, and change your decryption method to expect the same. Then the padding will be automatically removed, and you will never see it.
Upvotes: 3