forked from loafle/openapi-generator-original
fix ecdsa signing issue. (#16772)
This commit is contained in:
parent
f03cbea971
commit
1bbbb73690
@ -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>();
|
||||
|
@ -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>();
|
||||
|
@ -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>();
|
||||
|
@ -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>();
|
||||
|
@ -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>();
|
||||
|
@ -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>();
|
||||
|
@ -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>();
|
||||
|
@ -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>();
|
||||
|
@ -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>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user