This repository has been archived by the owner on Dec 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Still this Version: Added Some Small Features.
- Loading branch information
1 parent
1ba353e
commit b400726
Showing
3 changed files
with
79 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace LoCyanFrpDesktop.Utils | ||
{ | ||
internal class RSAEncryption | ||
{ | ||
public RSAEncryption() { | ||
string publicKey, privateKey; | ||
using (var rsa = new RSACryptoServiceProvider(4096)) | ||
{ | ||
publicKey = rsa.ToXmlString(false); // Public key | ||
privateKey = rsa.ToXmlString(true); // Private key | ||
} | ||
|
||
} | ||
public static byte[] EncryptData(string dataToEncrypt, string publicKey) | ||
{ | ||
byte[] encryptedData; | ||
using (var rsa = new RSACryptoServiceProvider(4096)) | ||
{ | ||
rsa.FromXmlString(publicKey); | ||
var dataToEncryptBytes = Encoding.UTF8.GetBytes(dataToEncrypt); | ||
encryptedData = rsa.Encrypt(dataToEncryptBytes, false); | ||
} | ||
return encryptedData; | ||
} | ||
|
||
public static string DecryptData(byte[] dataToDecrypt, string privateKey) | ||
{ | ||
byte[] decryptedData; | ||
using (var rsa = new RSACryptoServiceProvider(4096)) | ||
{ | ||
rsa.FromXmlString(privateKey); | ||
decryptedData = rsa.Decrypt(dataToDecrypt, false); | ||
} | ||
return Encoding.UTF8.GetString(decryptedData); | ||
} | ||
} | ||
} |