Initial Commit
This commit is contained in:
25
RSAExample/Program.cs
Normal file
25
RSAExample/Program.cs
Normal 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));
|
||||
}
|
||||
10
RSAExample/RSAExample.csproj
Normal file
10
RSAExample/RSAExample.csproj
Normal 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>
|
||||
Reference in New Issue
Block a user