public Task <IDeviceIdentity> GetAsync(string clientId, string username, X509Certificate clientCert, string keyStore, EndPoint clientAddress)
        {
            X509Certificate2 signedCert = new X509Certificate2(clientCert);

            CspParameters parameters = new CspParameters();

            parameters.KeyNumber        = (int)KeyNumber.Exchange;
            parameters.ProviderName     = "Microsoft Enhanced Cryptographic Provider v1.0";
            parameters.ProviderType     = 1;
            parameters.KeyContainerName = keyStore;
            RSACryptoServiceProvider cryptoProvider = new RSACryptoServiceProvider(4096, parameters);

            signedCert.PrivateKey = cryptoProvider;



            IotHubDeviceIdentity deviceIdentity;

            if (!IotHubDeviceIdentity.TryParse(username, out deviceIdentity) || !clientId.Equals(deviceIdentity.Id, StringComparison.Ordinal))
            {
                return(Task.FromResult(UnauthenticatedDeviceIdentity.Instance));
            }
            deviceIdentity.WithCertificate(signedCert);
            return(Task.FromResult <IDeviceIdentity>(deviceIdentity));
        }
        public Task <IDeviceIdentity> GetAsync(string clientId, string username, string password, EndPoint clientAddress)
        {
            IotHubDeviceIdentity deviceIdentity;

            if (!IotHubDeviceIdentity.TryParse(username, out deviceIdentity) || !clientId.Equals(deviceIdentity.Id, StringComparison.Ordinal))
            {
                return(Task.FromResult(UnauthenticatedDeviceIdentity.Instance));
            }
            deviceIdentity.WithDeviceKey(password);
            return(Task.FromResult <IDeviceIdentity>(deviceIdentity));
        }