Ejemplo n.º 1
0
        public async Task <byte[]> SignDataAsync(
            byte[] data, CancellationToken cancellationToken = default(CancellationToken))
        {
            var keyId = await GetKeyIdAsync(cancellationToken).ConfigureAwait(false);

            var url     = string.Format(SignBlobUrl, keyId);
            var request = new SignBlobRequest
            {
                BytesToSign = Convert.ToBase64String(data),
            };

            try
            {
                var response = await _httpClient.PostJsonAsync(url, request, cancellationToken)
                               .ConfigureAwait(false);

                var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                ThrowIfError(response, json);
                var parsed = NewtonsoftJsonSerializer.Instance.Deserialize <SignBlobResponse>(json);
                return(Convert.FromBase64String(parsed.Signature));
            }
            catch (HttpRequestException e)
            {
                throw new FirebaseException("Error while calling the IAM service.", e);
            }
        }
Ejemplo n.º 2
0
        public async Task <byte[]> SignDataAsync(
            byte[] data, CancellationToken cancellationToken = default(CancellationToken))
        {
            var keyId = await this.GetKeyIdAsync(cancellationToken).ConfigureAwait(false);

            var body = new SignBlobRequest
            {
                BytesToSign = Convert.ToBase64String(data),
            };
            var request = new HttpRequestMessage()
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri(string.Format(SignBlobUrl, keyId)),
                Content    = NewtonsoftJsonSerializer.Instance.CreateJsonHttpContent(body),
            };

            var response = await this.httpClient
                           .SendAndDeserializeAsync <SignBlobResponse>(request, cancellationToken)
                           .ConfigureAwait(false);

            return(Convert.FromBase64String(response.Result.Signature));
        }