Skip to content

Commit

Permalink
csharp: Add using to wrap HMACSHA1 instance (#582)
Browse files Browse the repository at this point in the history
* csharp: Add using for HMACSHA1

Signed-off-by: catcherwong <catcher_hwq@outlook.com>

* fix dotnet-format error

Signed-off-by: catcherwong <catcher_hwq@outlook.com>

---------

Signed-off-by: catcherwong <catcher_hwq@outlook.com>
  • Loading branch information
catcherwong authored Aug 4, 2023
1 parent 1e7aa33 commit 01deef8
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions csharp/rocketmq-client-csharp/Signature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ public static Dictionary<string, string> Sign(Client client)

var secretData = Encoding.ASCII.GetBytes(credentials.AccessSecret);
var data = Encoding.ASCII.GetBytes(time);
var signer = new HMACSHA1(secretData);
var digest = signer.ComputeHash(data);
var hmac = BitConverter.ToString(digest).Replace("-", "");
var authorization = $"{MetadataConstants.AlgorithmKey} " +
$"{MetadataConstants.CredentialKey}={credentials.AccessKey}, " +
$"{MetadataConstants.SignedHeadersKey}={MetadataConstants.DateTimeKey}, " +
$"{MetadataConstants.SignatureKey}={hmac}";
dictionary.Add(MetadataConstants.Authorization, authorization);
return dictionary;
using (var signer = new HMACSHA1(secretData))
{
var digest = signer.ComputeHash(data);
var hmac = BitConverter.ToString(digest).Replace("-", "");
var authorization = $"{MetadataConstants.AlgorithmKey} " +
$"{MetadataConstants.CredentialKey}={credentials.AccessKey}, " +
$"{MetadataConstants.SignedHeadersKey}={MetadataConstants.DateTimeKey}, " +
$"{MetadataConstants.SignatureKey}={hmac}";
dictionary.Add(MetadataConstants.Authorization, authorization);
return dictionary;
}
}
}
}

0 comments on commit 01deef8

Please sign in to comment.