fix ecdsa signing issue. (#16772)

This commit is contained in:
Ghufran Zahidi 2023-10-10 16:06:41 +05:30 committed by GitHub
parent f03cbea971
commit 1bbbb73690
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 48 additions and 6 deletions

View File

@ -373,8 +373,7 @@ namespace {{packageName}}.Client
else
ecdsa.ImportPkcs8PrivateKey(keyBytes, out byteCount);
var signedBytes = ecdsa.SignHash(dataToSign);
var derBytes = ConvertToECDSAANS1Format(signedBytes);
var derBytes = ecdsa.SignHash(dataToSign, DSASignatureFormat.Rfc3279DerSequence);
var signedString = System.Convert.ToBase64String(derBytes);
return signedString;
@ -384,6 +383,11 @@ namespace {{packageName}}.Client
{{/net60OrLater}}
}
/// <summary>
/// Convert ANS1 format to DER format. Not recommended to use because it generate inavlid signature occationally.
/// </summary>
/// <param name="signedBytes"></param>
/// <returns></returns>
private byte[] ConvertToECDSAANS1Format(byte[] signedBytes)
{
var derBytes = new List<byte>();

View File

@ -352,6 +352,11 @@ namespace Org.OpenAPITools.Client
throw new Exception("ECDSA signing is supported only on NETCOREAPP3_0 and above");
}
/// <summary>
/// Convert ANS1 format to DER format. Not recommended to use because it generate inavlid signature occationally.
/// </summary>
/// <param name="signedBytes"></param>
/// <returns></returns>
private byte[] ConvertToECDSAANS1Format(byte[] signedBytes)
{
var derBytes = new List<byte>();

View File

@ -352,6 +352,11 @@ namespace Org.OpenAPITools.Client
throw new Exception("ECDSA signing is supported only on NETCOREAPP3_0 and above");
}
/// <summary>
/// Convert ANS1 format to DER format. Not recommended to use because it generate inavlid signature occationally.
/// </summary>
/// <param name="signedBytes"></param>
/// <returns></returns>
private byte[] ConvertToECDSAANS1Format(byte[] signedBytes)
{
var derBytes = new List<byte>();

View File

@ -352,6 +352,11 @@ namespace Org.OpenAPITools.Client
throw new Exception("ECDSA signing is supported only on NETCOREAPP3_0 and above");
}
/// <summary>
/// Convert ANS1 format to DER format. Not recommended to use because it generate inavlid signature occationally.
/// </summary>
/// <param name="signedBytes"></param>
/// <returns></returns>
private byte[] ConvertToECDSAANS1Format(byte[] signedBytes)
{
var derBytes = new List<byte>();

View File

@ -352,6 +352,11 @@ namespace Org.OpenAPITools.Client
throw new Exception("ECDSA signing is supported only on NETCOREAPP3_0 and above");
}
/// <summary>
/// Convert ANS1 format to DER format. Not recommended to use because it generate inavlid signature occationally.
/// </summary>
/// <param name="signedBytes"></param>
/// <returns></returns>
private byte[] ConvertToECDSAANS1Format(byte[] signedBytes)
{
var derBytes = new List<byte>();

View File

@ -380,13 +380,17 @@ namespace Org.OpenAPITools.Client
else
ecdsa.ImportPkcs8PrivateKey(keyBytes, out byteCount);
var signedBytes = ecdsa.SignHash(dataToSign);
var derBytes = ConvertToECDSAANS1Format(signedBytes);
var derBytes = ecdsa.SignHash(dataToSign, DSASignatureFormat.Rfc3279DerSequence);
var signedString = System.Convert.ToBase64String(derBytes);
return signedString;
}
/// <summary>
/// Convert ANS1 format to DER format. Not recommended to use because it generate inavlid signature occationally.
/// </summary>
/// <param name="signedBytes"></param>
/// <returns></returns>
private byte[] ConvertToECDSAANS1Format(byte[] signedBytes)
{
var derBytes = new List<byte>();

View File

@ -352,6 +352,11 @@ namespace Org.OpenAPITools.Client
throw new Exception("ECDSA signing is supported only on NETCOREAPP3_0 and above");
}
/// <summary>
/// Convert ANS1 format to DER format. Not recommended to use because it generate inavlid signature occationally.
/// </summary>
/// <param name="signedBytes"></param>
/// <returns></returns>
private byte[] ConvertToECDSAANS1Format(byte[] signedBytes)
{
var derBytes = new List<byte>();

View File

@ -352,6 +352,11 @@ namespace Org.OpenAPITools.Client
throw new Exception("ECDSA signing is supported only on NETCOREAPP3_0 and above");
}
/// <summary>
/// Convert ANS1 format to DER format. Not recommended to use because it generate inavlid signature occationally.
/// </summary>
/// <param name="signedBytes"></param>
/// <returns></returns>
private byte[] ConvertToECDSAANS1Format(byte[] signedBytes)
{
var derBytes = new List<byte>();

View File

@ -380,13 +380,17 @@ namespace Org.OpenAPITools.Client
else
ecdsa.ImportPkcs8PrivateKey(keyBytes, out byteCount);
var signedBytes = ecdsa.SignHash(dataToSign);
var derBytes = ConvertToECDSAANS1Format(signedBytes);
var derBytes = ecdsa.SignHash(dataToSign, DSASignatureFormat.Rfc3279DerSequence);
var signedString = System.Convert.ToBase64String(derBytes);
return signedString;
}
/// <summary>
/// Convert ANS1 format to DER format. Not recommended to use because it generate inavlid signature occationally.
/// </summary>
/// <param name="signedBytes"></param>
/// <returns></returns>
private byte[] ConvertToECDSAANS1Format(byte[] signedBytes)
{
var derBytes = new List<byte>();