Ejemplo n.º 1
0
        Task <D2LSecurityToken> IPrivateKeyProvider.GetSigningCredentialsAsync()
        {
            var creationParams = new CngKeyCreationParameters()
            {
                ExportPolicy = CngExportPolicies.AllowPlaintextExport,
                KeyUsage     = CngKeyUsages.Signing
            };

            byte[] privateBlob;
            using (var cngKey = CngKey.Create(m_algorithm, null, creationParams)) {
                using (ECDsaCng ecDsa = new ECDsaCng(cngKey)) {
                    privateBlob = ecDsa.Key.Export(CngKeyBlobFormat.EccPrivateBlob);
                }
            }

            D2LSecurityToken result = m_d2lSecurityTokenFactory.Create(() => {
                using (var cng = CngKey.Import(privateBlob, CngKeyBlobFormat.EccPrivateBlob)) {
                    // ECDsaCng copies the CngKey, hence the using
                    var ecDsa = new ECDsaCng(cng);
                    var key   = new EcDsaSecurityKey(ecDsa);
                    return(new Tuple <AsymmetricSecurityKey, IDisposable>(key, ecDsa));
                }
            });

            return(Task.FromResult(result));
        }
        Task <D2LSecurityToken> IPrivateKeyProvider.GetSigningCredentialsAsync()
        {
            var ecdsa      = ECDsa.Create(m_curve);
            var parameters = ecdsa.ExportParameters(includePrivateParameters: true);

            D2LSecurityToken result = m_d2lSecurityTokenFactory.Create(() => {
                var ecDsa = ECDsa.Create(parameters);
                var key   = new ECDsaSecurityKey(ecDsa);
                return(new Tuple <AsymmetricSecurityKey, IDisposable>(key, ecDsa));
            });

            return(Task.FromResult(result));
        }
        Task <D2LSecurityToken> IPrivateKeyProvider.GetSigningCredentialsAsync()
        {
            RSAParameters privateKey;

            using (var csp = new RSACryptoServiceProvider(Constants.GENERATED_RSA_KEY_SIZE)
            {
                PersistKeyInCsp = false
            }) {
                privateKey = csp.ExportParameters(includePrivateParameters: true);
            }

            D2LSecurityToken result = m_d2lSecurityTokenFactory.Create(() => {
                var csp = new RSACryptoServiceProvider()
                {
                    PersistKeyInCsp = false
                };
                csp.ImportParameters(privateKey);
                var key = new RsaSecurityKey(csp);
                return(new Tuple <AsymmetricSecurityKey, IDisposable>(key, csp));
            });

            return(Task.FromResult(result));
        }