Initial Commit

This commit is contained in:
2024-10-20 23:08:53 +07:00
commit 6e3782b281
18 changed files with 883 additions and 0 deletions

25
RSAExample/Program.cs Normal file
View File

@@ -0,0 +1,25 @@
using System.Security.Cryptography;
using System.Text;
using (RSA rsa = RSA.Create())
{
rsa.KeySize = 2048;
// Export the public key
var publicKey = rsa.ExportRSAPublicKey();
Console.WriteLine("Public Key: " + Convert.ToBase64String(publicKey));
// Export the private key
var privateKey = rsa.ExportRSAPrivateKey();
Console.WriteLine("Private Key: " + Convert.ToBase64String(privateKey));
var message = "Some secret message";
Console.WriteLine("Original message: " + message);
// There are some of the paddings, but most common is PKCS
var encryptedBytes = rsa.Encrypt(Encoding.UTF8.GetBytes(message), RSAEncryptionPadding.Pkcs1);
Console.WriteLine("Encrypted message: " + Convert.ToBase64String(encryptedBytes));
var decryptedBytes = rsa.Decrypt(encryptedBytes, RSAEncryptionPadding.Pkcs1);
Console.WriteLine("Decrypted message: " + Encoding.UTF8.GetString(decryptedBytes));
}

View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>