public static RsaSecurityKey GetRsaSecurityKey() { RSACryptoServiceProvider publicAndPrivate = new RSACryptoServiceProvider(); RsaKeyGenerationResult keyGenerationResult = RsaKeyGenerationResult.GenerateKeys(); publicAndPrivate.FromXmlStringCustom(keyGenerationResult.PublicAndPrivateKey); return(new RsaSecurityKey(publicAndPrivate)); }
public Task <SigningCredentials> GetSigningCredentialsAsync() { var handler = new JwtSecurityTokenHandler(); RSACryptoServiceProvider publicAndPrivate = new RSACryptoServiceProvider(); RsaKeyGenerationResult keyGenerationResult = RsaKeyGenerationResult.GenerateKeys(); publicAndPrivate.FromXmlStringCustom(keyGenerationResult.PublicAndPrivateKey); var s = new SigningCredentials(new RsaSecurityKey(publicAndPrivate), SecurityAlgorithms.RsaSha256); return(Task.FromResult(s)); }
public Task <IEnumerable <SecurityKey> > GetValidationKeysAsync() { RSACryptoServiceProvider publicAndPrivate = new RSACryptoServiceProvider(); RsaKeyGenerationResult keyGenerationResult = RsaKeyGenerationResult.GenerateKeys(); publicAndPrivate.FromXmlStringCustom(keyGenerationResult.PublicAndPrivateKey); var keys = new List <SecurityKey>() { new RsaSecurityKey(publicAndPrivate) }; return(Task.FromResult(keys.AsEnumerable())); }
public static RsaKeyGenerationResult GenerateKeys() { RSAParameters publicKey; RsaKeyGenerationResult result; //using (RSA rsa = RSA.Create()) //{ // rsa.KeySize = 2048; // publicKey = rsa.ExportParameters(true); // result = new RsaKeyGenerationResult // { // PublicAndPrivateKey = rsa.ToXmlString(true), // PublicKeyOnly = rsa.ToXmlString(false) // }; //} RSACryptoServiceProvider myRSA = new RSACryptoServiceProvider(2048); publicKey = myRSA.ExportParameters(true); result = new RsaKeyGenerationResult { PublicAndPrivateKey = myRSA.ToXmlStringCustom(true), PublicKeyOnly = myRSA.ToXmlStringCustom(true) }; return(result); }