Exemple #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));
        }
Exemple #2
0
        internal override D2LSecurityToken ToSecurityToken()
        {
            var token = new D2LSecurityToken(
                id: Id,
                validFrom: DateTime.UtcNow,
                validTo: ExpiresAt ?? DateTime.UtcNow + Constants.REMOTE_KEY_MAX_LIFETIME,
                keyFactory: () => {
                var cng = BuildEcDsaCng();
                var key = new EcDsaSecurityKey(cng);
                return(new Tuple <AsymmetricSecurityKey, IDisposable>(key, cng));
            }
                );

            return(token);
        }
		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 );
		}
		internal override D2LSecurityToken ToSecurityToken() {

			var token = new D2LSecurityToken(
				id: Id,
				validFrom: DateTime.UtcNow,
				validTo: ExpiresAt ?? DateTime.UtcNow + Constants.REMOTE_KEY_MAX_LIFETIME,
				keyFactory: () => {
					var cng = BuildEcDsaCng();
					var key = new EcDsaSecurityKey( cng );
					return new Tuple<AsymmetricSecurityKey, IDisposable>( key, cng );
				}
			);
			
			return token;
		}