Geni Lou

Geni Lou

  • NA
  • 101
  • 24.1k

Generate Signature with RSA

Nov 17 2021 3:41 PM

How can I generate a signature with my existing private key? will the code below works?

string privateKeyString = File.ReadAllText("private.key");
TextReader priReader = new StringReader(privateKeyString)
PemReader pemReader = new PemReader(priReader);
var obj = pemReader.ReadObject();
var pri = obj as RsaPrivateCrtKeyParameters;

Sha256Digest digest = new Sha256Digest();

RsaDigestSigner signer = new RsaDigestSigner(digest);
signer.Init(true, pri);
byte[] sig = signer.GenerateSignature();

var signature = Convert.ToBase64String(sig);


Answers (1)