I am having this issue, I am making a demo client-server application that include end-to-end encryption for word document. I can send word document without images properly but I can’t with files that contain images. I don’t think it is due to encryptor/decryptor because I can still encrypt and decrypt files that don’t contain images and it’s maybe due to sending and receiving function itself, here my code:
Sending files function:
` private void SendFileButton_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog
{
Filter = "Word Documents|*.docx"
};
if (openFileDialog.ShowDialog() == true)
{
string filePath = openFileDialog.FileName;
byte[] encryptedData = EncryptData(filePath);
stream.Write(encryptedData, 0, encryptedData.Length);
MessageBox.Show("File sent!");
}
}`
Receiving files function:
private void ReceiveFileButton_Click(object sender, RoutedEventArgs e)
{
byte[] buffer = new byte[client.ReceiveBufferSize];
int bytesRead = stream.Read(buffer, 0, buffer.Length);
byte[] encryptedData = new byte[bytesRead];
Array.Copy(buffer, encryptedData, bytesRead);
byte[] decryptedData = DecryptData(encryptedData);
Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog
{
Filter = "Word Documents|*.docx"
};
if (saveFileDialog.ShowDialog() == true)
{
string filePath = saveFileDialog.FileName;
File.WriteAllBytes(filePath, decryptedData);
MessageBox.Show("File received and saved!");
}
}`
I tried to check all over the encryptor, decryptor. I want to send encrypted word documents that contains images in order to decrypt it. When I tried to send them, and I click receive button, it say “padding is not invalid and cannot be removed”.
PIPO PoPI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.