使用doc或pdf库我无法加密文件及其格式我只能从doc读取文本文件并将其存储在字符串中并传递给加密函数和解密函数
else if (comboBox1.Text == ".doc")
{
var application = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document document = application.Documents.Open(textBox1.Text);
// Loop through all words in the document.
int count = document.Words.Count;
string s2 = " ";
for (int i = 1; i <= count; i++)
{
// Write the word.
string text = document.Words[i].Text;
Console.WriteLine("Word {0} = {1}", i, text);
s2 = s2 + text;
}
MessageBox.Show(s2);
txtSend.Text = s2;
// Close word.
application.Quit();
}
string plainText=txtSend.Text;
CryptLib _crypt = new CryptLib();
//string plainText = "This is the text to be encrypted";
String iv = CryptLib.GenerateRandomIV(16); //16 bytes = 128 bits
string key = CryptLib.getHashSha256("my secret key", 31); //32 bytes = 256 bits
MessageBox.Show(plainText);//////////////////////
String cypherText = _crypt.encrypt(plainText, key, iv);
Console.WriteLine("iv=" + iv);
Console.WriteLine("key=" + key);
Console.WriteLine("Cypher text=" + cypherText);
MessageBox.Show(cypherText);
textBox1.Text = cypherText;
Console.WriteLine("Plain text =" + _crypt.decrypt(cypherText, key, iv));
MessageBox.Show(_crypt.decrypt(cypherText, key, iv));
textBox2.Text = _crypt.decrypt(cypherText, key, iv);