- [C#] Viết ứng dụng Auto Fill list Textbox from clipboard Winform
- [TOOL] Chia sẻ phần mềm thay đổi thông tin cấu hình máy tính
- [C#] Hướng dẫn Export dữ liệu ra file Microsoft Word Template
- [C#] Chia sẻ source code tool kiểm tra domain website
- [C#] Hướng dẫn tạo file PDF sử dụng thư viện QuestPDF
- [C#] Hướng dẫn tạo ứng dụng dock windows giống Taskbar
- [C#] Chia sẻ source code sử dụng Object Listview trên Winform
- [VB.NET] Chia sẻ source code quản lý thu chi mô hình 3 lớp Winform
- [DATABASE] Xóa lịch sử danh sách đăng nhập tài khoản trên SMSS Sqlserver Management Studio
- [C#] Sử dụng FolderBrowserDialog Vista trên Winform
- [DEVEXPRESS] Chia sẻ tool Winform UI Templates Early Access Preview (EAP)
- [C#] Chia sẻ source code Spin Content (Trộn nội dung văn bản theo từ đồng nghĩa) trên Winform
- [VB.NET] Chia sẻ source code lịch âm dương và hẹn lịch nhắc việc
- [C#] Hướng dẫn đọc thông số thiết bị Thiết bị kiểm tra Pin (HIOKI BATTERY HiTESTER BT3562)
- [VB.NET] Hướng dẫn giải captcha sử dụng dịch vụ AZCaptcha API trên winform
- [C#] Hướng dẫn chứng thực đăng nhập ứng dụng bằng vân tay (Finger Print) trên máy tính
- [C#] Color Thief cách xuất màu sắc thiết kế từ hình ảnh
- [C#] Cách tạo bản quyền và cho phép dùng thử ứng dụng Winform
- [C#] Hướng dẫn sử dụng trình duyệt web Chrome convert HTML sang tập tin file PDF
- [C#] Kết nôi điện thoại Android, IOS với App Winform via Bluetooth
[C#] Mã hóa RSA trong lập trình Csharp
Xin chào các bạn, bài viết hôm nay, mình xin chia sẽ đến các bạn source code mã hóa RSA trong lập trình C#. Bài viết này, mình cũng đã có viết một bài hướng dẫn bên ngôn ngữ VB.NET.
Các bạn có thể tham khảo thêm bằng cách gõ từ khóa RSA trên thanh tìm kiếm nhé.
Nếu bạn nào chưa biết RSA là gì? và cách mã hóa và giải mã như thế nào, các bạn có thể tham khảo thêm ở link này "Mã hóa RSA".
Giao diện demo ứng dụng Mã hóa RSA C#:
Source code mã hóa RSA C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
namespace RSAEncryption
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
#region-----Encryptionand Decryption Function-----
static public byte[] Encryption(byte[] Data, RSAParameters RSAKey, bool DoOAEPPadding)
{
try
{
byte[] encryptedData;
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
RSA.ImportParameters(RSAKey);
encryptedData = RSA.Encrypt(Data, DoOAEPPadding);
}
return encryptedData;
}
catch (CryptographicException e)
{
Console.WriteLine(e.Message);
return null;
}
}
static public byte[] Decryption(byte[] Data, RSAParameters RSAKey, bool DoOAEPPadding)
{
try
{
byte[] decryptedData;
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
RSA.ImportParameters(RSAKey);
decryptedData = RSA.Decrypt(Data, DoOAEPPadding);
}
return decryptedData;
}
catch (CryptographicException e)
{
Console.WriteLine(e.ToString());
return null;
}
}
#endregion
#region--variables area
UnicodeEncoding ByteConverter = new UnicodeEncoding();
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
byte[] plaintext;
byte[] encryptedtext;
#endregion
#region-- Function Implemantation
private void button1_Click(object sender, EventArgs e)
{
plaintext = ByteConverter.GetBytes(txtplain.Text);
encryptedtext = Encryption(plaintext, RSA.ExportParameters(false), false);
txtencrypt.Text = ByteConverter.GetString(encryptedtext);
}
private void button2_Click(object sender, EventArgs e)
{
byte[] decryptedtex = Decryption(encryptedtext, RSA.ExportParameters(true), false);
txtdecrypt.Text = ByteConverter.GetString(decryptedtex);
}
#endregion
}
}
HAPPY CODING