-
21-04-2013, 03:29 PM #1Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Lỗi ArgumentException was Unhandled khóa Key trong mã hóa AES
AE chỉ giúp mình lỗi như này là sửa ở đâu
private void buttonEncrypt_Click(object sender, EventArgs e)
{
string password = textBoxKey.Text;
string salt = textBoxSalt.Text;
string plainText = textBoxInput.Text;
byte[]plainBytes=Encoding.ASCII.GetBytes(plainText);
//Rfc2898DeriveBytes: Used to Generate Strong Keys
//báo lỗi ở dòng bôi đậm này
Rfc2898DeriveBytes rfc = new Rfc2898DeriveBytes(password,
Encoding.ASCII.GetBytes(salt));//Non-English Alfhabets Will not Work on ASCII Encoding
SymmetricAlgorithm Alg = GetSelectedAlgorithm();
Alg.Key = rfc.GetBytes(Alg.KeySize / 8);
Alg.IV = rfc.GetBytes(Alg.BlockSize / 8);
MemoryStream strCiphered = new MemoryStream();//To Store Encrypted Data
CryptoStream strCrypto = new CryptoStream(strCiphered,
Alg.CreateEncryptor(), CryptoStreamMode.Write);
strCrypto.Write(plainBytes, 0, plainBytes.Length);
strCrypto.Close();
textBoxCiphered.Text = Convert.ToBase64String(strCiphered.ToArray());
strCiphered.Close();
}
//Simple Private-Key Decryption Operation
private void buttonDecrypt_Click(object sender, EventArgs e)
{
string password = textBoxKey.Text;
string salt = textBoxSalt.Text;
string cipheredText = textBoxCiphered.Text;
byte[] cipheredBytes = Convert.FromBase64String(cipheredText);
//Rfc2898DeriveBytes: Used to Generate Strong Keys
Rfc2898DeriveBytes rfc = new Rfc2898DeriveBytes(password,
Encoding.ASCII.GetBytes(salt));//Non-English Alfhabets Will not Work on ASCII Encoding
SymmetricAlgorithm Alg = GetSelectedAlgorithm();
Alg.Key = rfc.GetBytes(Alg.KeySize / 8);
Alg.IV = rfc.GetBytes(Alg.BlockSize / 8);
MemoryStream strDeciphered = new MemoryStream();//To Store Decrypted Data
CryptoStream strCrypto = new CryptoStream(strDeciphered,
Alg.CreateDecryptor(), CryptoStreamMode.Write);
strCrypto.Write(cipheredBytes, 0, cipheredBytes.Length);
strCrypto.Close();
textBoxDeciphered.Text = Encoding.ASCII.GetString(strDeciphered.ToArray());
strDeciphered.Close();
}View more random threads:
- Lỗi The project file could not be loaded. Root element is missing.
- Làm thế nào luôn focus vào form có nhiều button
- Có thể thêm file ảnh vào xml được ko?
- hiện bảng thông báo trước khi xóa dữ liệu
- làm sao lưu hình ảnh xuống Database là Access 2003
- ý nghĩa của câu lệnh Environment.TickCount trong C# như thế nào?
- bản quyền devexpress
- Cách xoay bản số xe nằm ngay đường thẳng ???
- Cách làm hàm Save Game và Load Game?
- Remoting trong mô hình 3 lớp như thế nào?
Ngọc Bích xanh bản chất thuộc dòng đá đá hoa (jade). Và cẩm thạch là tên gọi chung của ngọc bích. Vì thực chất chúng thuộc dòng đá đa khoáng được hình thành từ chất Silicat dưới dạng dioxy. Ngọc bích...
Chia sẻ Vòng tay ngọc bích xanh là...