Skip to content

Instantly share code, notes, and snippets.

View cagegit's full-sized avatar
🎯
Focusing

jetcage cagegit

🎯
Focusing
  • Beijing
View GitHub Profile
@cagegit
cagegit / decrypt.cs
Created December 8, 2022 09:31
RSA decrypt with private key in c# or net core
public static void Main()
{
var privateKey = "your privateKey string";
privateKey = $"-----BEGIN RSA PRIVATE KEY-----{Environment.NewLine}{privateKey}{Environment.NewLine}-----END RSA PRIVATE KEY-----";
var key = "your key need to be decrypt";
var rsa = RSA.Create();
rsa.ImportFromPem(privateKey.ToCharArray());
var decryptedBytes = rsa.Decrypt(
Convert.FromBase64String(key),
RSAEncryptionPadding.Pkcs1