C# “Bad Data” exception when decrypting encrypted file

前端 未结 3 1492
眼角桃花
眼角桃花 2021-01-15 05:06

Hey I\'m very new to encryption and decryption, or even the c# language to be honest. Basically, I have a tcp chat server that \"saves\" logs and encrypts the text file. Thi

3条回答
  •  甜味超标
    2021-01-15 05:36

    What fixed my issue was calling FlushFinalBlock on cryptostream, When creating the file

                    CryptoStream cryptostream = new CryptoStream(memoryStream, this._encryptionKeyHelper.Encryptor(), CryptoStreamMode.Write);
    
                xmlser.Serialize(cryptostream, builderObject);
    
                cryptostream.FlushFinalBlock();
    

提交回复
热议问题