예제 #1
0
        public async Task SignAsync()
        {
            byte[] data = Encoding.UTF8.GetBytes("some text");
            using (HttpClient httpClient = HttpClientHelper.GetHttpClient(this.serverUri))
            {
                var workload = new HttpWorkloadClient(httpClient)
                {
                    BaseUrl = HttpClientHelper.GetBaseUrl(this.serverUri)
                };

                var payload = new SignRequest()
                {
                    Algo  = SignRequestAlgo.HMACSHA256,
                    Data  = data,
                    KeyId = "primary"
                };
                SignResponse response = await workload.SignAsync(WorkloadApiVersion, "testModule", "1", payload);

                string expected;
                using (var algorithm = new HMACSHA256(Encoding.UTF8.GetBytes("key")))
                {
                    expected = Convert.ToBase64String(algorithm.ComputeHash(data));
                }

                Assert.Equal(expected, Convert.ToBase64String(response.Digest));
            }
        }
예제 #2
0
        public override async Task <string> SignAsync(string keyId, string algorithm, string data)
        {
            var signRequest = new SignRequest
            {
                KeyId = keyId,
                Algo  = this.GetSignatureAlgorithm(algorithm),
                Data  = Encoding.UTF8.GetBytes(data)
            };

            using (HttpClient httpClient = HttpClientHelper.GetHttpClient(this.WorkloadUri))
            {
                var edgeletHttpClient = new HttpWorkloadClient(httpClient)
                {
                    BaseUrl = HttpClientHelper.GetBaseUrl(this.WorkloadUri)
                };
                SignResponse response = await this.Execute(() => edgeletHttpClient.SignAsync(this.Version.Name, this.ModuleId, this.ModuleGenerationId, signRequest), "SignAsync");

                return(Convert.ToBase64String(response.Digest));
            }
        }
예제 #3
0
        async Task <SignResponse> SignAsyncWithRetry(HttpWorkloadClient hsmHttpClient, SignRequest signRequest)
        {
            var          transientRetryPolicy = new RetryPolicy(TransientErrorDetectionStrategy, TransientRetryStrategy);
            SignResponse response             = await transientRetryPolicy.ExecuteAsync(() => hsmHttpClient.SignAsync(this.apiVersion, this.moduleId, this.generationId, signRequest));

            return(response);
        }