private void buttonEncryptAes_Click(object sender, EventArgs e) { alice.plaintext = textBoxPlainTextAlice.Text; if (!string.IsNullOrEmpty(alice.plaintext) && alice.BytesSessionkey != null) { if (aesMode == CipherMode.OFB) { //работает только в bouncyCastle // Encrypt the string to an array of bytes. byte[] encrypted = AES_bouncy_OFB.encrypt(alice.plaintext, alice.BytesSessionkey);//AES.EncryptStringToBytes_Aes(alice.plaintext, alice.BytesSessionkey); alice.encryptedMessage = Convert.ToBase64String(encrypted); alice.encryptedMessageBytes = encrypted; textBoxEncryptedMessageAlice.Text = alice.encryptedMessage; } else { //byte[] bytesKey = Encoding.UTF8.GetBytes(sessionkey); // Encrypt the string to an array of bytes. byte[] encrypted = AES.EncryptStringToBytes_Aes(alice.plaintext, alice.BytesSessionkey); alice.encryptedMessage = Convert.ToBase64String(encrypted); alice.encryptedMessageBytes = encrypted; textBoxEncryptedMessageAlice.Text = alice.encryptedMessage; } } else { MessageBox.Show("plaintext or session key empty"); } }
internal string decryptMessage(CipherMode aesMode) { if (aesMode == CipherMode.OFB) { var res = AES_bouncy_OFB.decrypt(encryptedMessageBytes, decryptedSessionKeyBytes); decryptedMessage = res; return(res); } else { var res = AES.DecryptStringFromBytes_Aes(encryptedMessageBytes, decryptedSessionKeyBytes); decryptedMessage = res; return(res); } }