@@ -250,10 +250,8 @@ public static AWS4aSigningResult ComputeSignature(ImmutableCredentials credentia
250
250
251
251
metrics ? . AddProperty ( Metric . StringToSign , stringToSignBuilder ) ;
252
252
253
- using var key = ComputeSigningKey ( credentials ) ;
254
-
255
253
var stringToSign = stringToSignBuilder . ToString ( ) ;
256
- var signature = AWSSDKUtils . ToHex ( SignBlob ( key , stringToSign ) , true ) ;
254
+ var signature = AWSSDKUtils . ToHex ( SignBlob ( credentials , stringToSign ) , true ) ;
257
255
return new AWS4aSigningResult ( credentials . AccessKey , signedAt , signedHeaders , scope , regionSet , signature , service , "" , credentials ) ;
258
256
}
259
257
@@ -309,9 +307,10 @@ private static int CompareConstantTime(byte[] lhs, byte[] rhs)
309
307
/// <summary>
310
308
/// Compute and return the signing key for the request.
311
309
/// </summary>
312
- /// <param name="credentials">The credentials.</param>
310
+ /// <param name="awsAccessKey">Access key credential.</param>
311
+ /// <param name="awsSecretAccessKey">Secret access key credential.</param>
313
312
/// <returns>Computed signing key</returns>
314
- public static ECDsa ComputeSigningKey ( ImmutableCredentials credentials )
313
+ public static ECDsa ComputeSigningKey ( string awsAccessKey , string awsSecretAccessKey )
315
314
{
316
315
byte [ ] kvalue = null ;
317
316
byte [ ] ksecret = null ;
@@ -328,7 +327,7 @@ public static ECDsa ComputeSigningKey(ImmutableCredentials credentials)
328
327
idx += 4 ;
329
328
idx += Encoding . UTF8 . GetBytes ( AWS4aAlgorithmTag , 0 , AWS4aAlgorithmTag . Length , kvalue , idx ) ;
330
329
idx ++ ;
331
- idx += Encoding . UTF8 . GetBytes ( credentials . AccessKey , 0 , credentials . AccessKey . Length , kvalue , idx ) ;
330
+ idx += Encoding . UTF8 . GetBytes ( awsAccessKey , 0 , awsAccessKey . Length , kvalue , idx ) ;
332
331
ref byte counterValue = ref kvalue [ idx ++ ] ;
333
332
kvalue [ idx + 2 ] = 1 ;
334
333
@@ -366,22 +365,23 @@ public static ECDsa ComputeSigningKey(ImmutableCredentials credentials)
366
365
}
367
366
368
367
/// <summary>
369
- /// Returns the ECDSA signature for an arbitrary blob using the specified key
368
+ /// Returns the ECDSA signature for an arbitrary blob using the specified credentials.
370
369
/// </summary>
371
- /// <param name="key ">The key to use.</param>
370
+ /// <param name="credentials ">The credentials to use.</param>
372
371
/// <param name="data">The data to sign.</param>
373
- public static byte [ ] SignBlob ( ECDsa key , string data )
372
+ public static byte [ ] SignBlob ( ImmutableCredentials credentials , string data )
374
373
{
375
- return SignBlob ( key , Encoding . UTF8 . GetBytes ( data ) ) ;
374
+ return SignBlob ( credentials , Encoding . UTF8 . GetBytes ( data ) ) ;
376
375
}
377
376
378
377
/// <summary>
379
- /// Returns the ECDSA signature for an arbitrary blob using the specified key
378
+ /// Returns the ECDSA signature for an arbitrary blob using the specified credentials.
380
379
/// </summary>
381
- /// <param name="key ">The key to use.</param>
380
+ /// <param name="credentials ">The credentials to use.</param>
382
381
/// <param name="data">The data to sign.</param>
383
- public static byte [ ] SignBlob ( ECDsa key , byte [ ] data )
382
+ public static byte [ ] SignBlob ( ImmutableCredentials credentials , byte [ ] data )
384
383
{
384
+ var key = credentials . AWS4aSigningKey ??= ComputeSigningKey ( credentials . AccessKey , credentials . SecretKey ) ;
385
385
return key . SignData ( data , HashAlgorithmName . SHA256 ) ;
386
386
}
387
387
#endregion
0 commit comments