Signing a string with RSA private key on .NET?

2019-01-15 22:36发布

byte[] plaintext = System.Text.Encoding.UTF8.GetBytes("AAAAAAAAAAAAA");

TextReader trCer = new StreamReader(@"AA.key"); //key in PEM format

PemReader rdCer = new PemReader(trCer);

AsymmetricCipherKeyPair o = rdCer.ReadObject() as AsymmetricCipherKeyPair;

ISigner sig = SignerUtilities.GetSigner("MD5WithRSAEncryption");

sig.Init(true, o.Private);

sig.BlockUpdate(plaintext,0,plaintext.Length);

Byte[] signature  = sig.GenerateSignature();

string signatureHeader = Convert.ToBase64String(signature);

Console.WriteLine(signatureHeader);

How I can use a key in DER format? I'm using the library BouncyCastle.Crypto.dll

`

0条回答
登录 后发表回答