diff --git a/modules/openapi-generator/src/main/resources/csharp/HttpSigningConfiguration.mustache b/modules/openapi-generator/src/main/resources/csharp/HttpSigningConfiguration.mustache
index 4bc8b396e09..33791a90857 100644
--- a/modules/openapi-generator/src/main/resources/csharp/HttpSigningConfiguration.mustache
+++ b/modules/openapi-generator/src/main/resources/csharp/HttpSigningConfiguration.mustache
@@ -102,14 +102,13 @@ namespace {{packageName}}.Client
const string HEADER_AUTHORIZATION = "Authorization";
//Read the api key from the file
- if(string.IsNullOrEmpty(this.KeyString))
+ if(File.Exists(KeyFilePath))
{
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
}
-
- if(string.IsNullOrEmpty(KeyString))
+ else if(string.IsNullOrEmpty(KeyString))
{
- throw new Exception("No API key has been provided.");
+ throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
}
//Hash table to store singed headers
@@ -317,6 +316,10 @@ namespace {{packageName}}.Client
private string GetRSASignature(byte[] stringToSign)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
if (SigningAlgorithm == "RSASSA-PSS")
{
@@ -342,8 +345,10 @@ namespace {{packageName}}.Client
private string GetECDSASignature(byte[] dataToSign)
{
{{#net60OrLater}}
- if (!File.Exists(KeyFilePath))
- throw new Exception("key file path does not exist.");
+ if (!File.Exists(KeyFilePath) && string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
var keyStr = KeyString;
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
@@ -443,6 +448,11 @@ namespace {{packageName}}.Client
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
+
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
const string pempubfooter = "-----END PUBLIC KEY-----";
bool isPrivateKeyFile = true;
diff --git a/samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 7c8668488ee..256f338e181 100644
--- a/samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -110,14 +110,13 @@ namespace Org.OpenAPITools.Client
const string HEADER_AUTHORIZATION = "Authorization";
//Read the api key from the file
- if(string.IsNullOrEmpty(this.KeyString))
+ if(File.Exists(KeyFilePath))
{
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
}
-
- if(string.IsNullOrEmpty(KeyString))
+ else if(string.IsNullOrEmpty(KeyString))
{
- throw new Exception("No API key has been provided.");
+ throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
}
//Hash table to store singed headers
@@ -325,6 +324,10 @@ namespace Org.OpenAPITools.Client
private string GetRSASignature(byte[] stringToSign)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
if (SigningAlgorithm == "RSASSA-PSS")
{
@@ -412,6 +415,11 @@ namespace Org.OpenAPITools.Client
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
+
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
const string pempubfooter = "-----END PUBLIC KEY-----";
bool isPrivateKeyFile = true;
diff --git a/samples/client/petstore/csharp/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 7c8668488ee..256f338e181 100644
--- a/samples/client/petstore/csharp/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient-httpclient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -110,14 +110,13 @@ namespace Org.OpenAPITools.Client
const string HEADER_AUTHORIZATION = "Authorization";
//Read the api key from the file
- if(string.IsNullOrEmpty(this.KeyString))
+ if(File.Exists(KeyFilePath))
{
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
}
-
- if(string.IsNullOrEmpty(KeyString))
+ else if(string.IsNullOrEmpty(KeyString))
{
- throw new Exception("No API key has been provided.");
+ throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
}
//Hash table to store singed headers
@@ -325,6 +324,10 @@ namespace Org.OpenAPITools.Client
private string GetRSASignature(byte[] stringToSign)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
if (SigningAlgorithm == "RSASSA-PSS")
{
@@ -412,6 +415,11 @@ namespace Org.OpenAPITools.Client
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
+
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
const string pempubfooter = "-----END PUBLIC KEY-----";
bool isPrivateKeyFile = true;
diff --git a/samples/client/petstore/csharp/OpenAPIClient-net47/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/OpenAPIClient-net47/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 7c8668488ee..256f338e181 100644
--- a/samples/client/petstore/csharp/OpenAPIClient-net47/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient-net47/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -110,14 +110,13 @@ namespace Org.OpenAPITools.Client
const string HEADER_AUTHORIZATION = "Authorization";
//Read the api key from the file
- if(string.IsNullOrEmpty(this.KeyString))
+ if(File.Exists(KeyFilePath))
{
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
}
-
- if(string.IsNullOrEmpty(KeyString))
+ else if(string.IsNullOrEmpty(KeyString))
{
- throw new Exception("No API key has been provided.");
+ throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
}
//Hash table to store singed headers
@@ -325,6 +324,10 @@ namespace Org.OpenAPITools.Client
private string GetRSASignature(byte[] stringToSign)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
if (SigningAlgorithm == "RSASSA-PSS")
{
@@ -412,6 +415,11 @@ namespace Org.OpenAPITools.Client
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
+
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
const string pempubfooter = "-----END PUBLIC KEY-----";
bool isPrivateKeyFile = true;
diff --git a/samples/client/petstore/csharp/OpenAPIClient-net48/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/OpenAPIClient-net48/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 7c8668488ee..256f338e181 100644
--- a/samples/client/petstore/csharp/OpenAPIClient-net48/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient-net48/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -110,14 +110,13 @@ namespace Org.OpenAPITools.Client
const string HEADER_AUTHORIZATION = "Authorization";
//Read the api key from the file
- if(string.IsNullOrEmpty(this.KeyString))
+ if(File.Exists(KeyFilePath))
{
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
}
-
- if(string.IsNullOrEmpty(KeyString))
+ else if(string.IsNullOrEmpty(KeyString))
{
- throw new Exception("No API key has been provided.");
+ throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
}
//Hash table to store singed headers
@@ -325,6 +324,10 @@ namespace Org.OpenAPITools.Client
private string GetRSASignature(byte[] stringToSign)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
if (SigningAlgorithm == "RSASSA-PSS")
{
@@ -412,6 +415,11 @@ namespace Org.OpenAPITools.Client
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
+
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
const string pempubfooter = "-----END PUBLIC KEY-----";
bool isPrivateKeyFile = true;
diff --git a/samples/client/petstore/csharp/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index d98d2815297..0685800345a 100644
--- a/samples/client/petstore/csharp/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient-net5.0/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -110,14 +110,13 @@ namespace Org.OpenAPITools.Client
const string HEADER_AUTHORIZATION = "Authorization";
//Read the api key from the file
- if(string.IsNullOrEmpty(this.KeyString))
+ if(File.Exists(KeyFilePath))
{
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
}
-
- if(string.IsNullOrEmpty(KeyString))
+ else if(string.IsNullOrEmpty(KeyString))
{
- throw new Exception("No API key has been provided.");
+ throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
}
//Hash table to store singed headers
@@ -325,6 +324,10 @@ namespace Org.OpenAPITools.Client
private string GetRSASignature(byte[] stringToSign)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
if (SigningAlgorithm == "RSASSA-PSS")
{
@@ -349,8 +352,10 @@ namespace Org.OpenAPITools.Client
/// ECDSA signature
private string GetECDSASignature(byte[] dataToSign)
{
- if (!File.Exists(KeyFilePath))
- throw new Exception("key file path does not exist.");
+ if (!File.Exists(KeyFilePath) && string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
var keyStr = KeyString;
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
@@ -446,6 +451,11 @@ namespace Org.OpenAPITools.Client
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
+
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
const string pempubfooter = "-----END PUBLIC KEY-----";
bool isPrivateKeyFile = true;
diff --git a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 7c8668488ee..256f338e181 100644
--- a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -110,14 +110,13 @@ namespace Org.OpenAPITools.Client
const string HEADER_AUTHORIZATION = "Authorization";
//Read the api key from the file
- if(string.IsNullOrEmpty(this.KeyString))
+ if(File.Exists(KeyFilePath))
{
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
}
-
- if(string.IsNullOrEmpty(KeyString))
+ else if(string.IsNullOrEmpty(KeyString))
{
- throw new Exception("No API key has been provided.");
+ throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
}
//Hash table to store singed headers
@@ -325,6 +324,10 @@ namespace Org.OpenAPITools.Client
private string GetRSASignature(byte[] stringToSign)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
if (SigningAlgorithm == "RSASSA-PSS")
{
@@ -412,6 +415,11 @@ namespace Org.OpenAPITools.Client
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
+
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
const string pempubfooter = "-----END PUBLIC KEY-----";
bool isPrivateKeyFile = true;
diff --git a/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index 7c8668488ee..256f338e181 100644
--- a/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -110,14 +110,13 @@ namespace Org.OpenAPITools.Client
const string HEADER_AUTHORIZATION = "Authorization";
//Read the api key from the file
- if(string.IsNullOrEmpty(this.KeyString))
+ if(File.Exists(KeyFilePath))
{
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
}
-
- if(string.IsNullOrEmpty(KeyString))
+ else if(string.IsNullOrEmpty(KeyString))
{
- throw new Exception("No API key has been provided.");
+ throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
}
//Hash table to store singed headers
@@ -325,6 +324,10 @@ namespace Org.OpenAPITools.Client
private string GetRSASignature(byte[] stringToSign)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
if (SigningAlgorithm == "RSASSA-PSS")
{
@@ -412,6 +415,11 @@ namespace Org.OpenAPITools.Client
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
+
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
const string pempubfooter = "-----END PUBLIC KEY-----";
bool isPrivateKeyFile = true;
diff --git a/samples/client/petstore/csharp/OpenAPIClientCore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs b/samples/client/petstore/csharp/OpenAPIClientCore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
index d98d2815297..0685800345a 100644
--- a/samples/client/petstore/csharp/OpenAPIClientCore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
+++ b/samples/client/petstore/csharp/OpenAPIClientCore/src/Org.OpenAPITools/Client/HttpSigningConfiguration.cs
@@ -110,14 +110,13 @@ namespace Org.OpenAPITools.Client
const string HEADER_AUTHORIZATION = "Authorization";
//Read the api key from the file
- if(string.IsNullOrEmpty(this.KeyString))
+ if(File.Exists(KeyFilePath))
{
this.KeyString = ReadApiKeyFromFile(KeyFilePath);
}
-
- if(string.IsNullOrEmpty(KeyString))
+ else if(string.IsNullOrEmpty(KeyString))
{
- throw new Exception("No API key has been provided.");
+ throw new Exception("No API key has been provided. Supply it using either KeyFilePath or KeyString");
}
//Hash table to store singed headers
@@ -325,6 +324,10 @@ namespace Org.OpenAPITools.Client
private string GetRSASignature(byte[] stringToSign)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
RSA rsa = GetRSAProviderFromPemFile(KeyString, KeyPassPhrase);
if (SigningAlgorithm == "RSASSA-PSS")
{
@@ -349,8 +352,10 @@ namespace Org.OpenAPITools.Client
/// ECDSA signature
private string GetECDSASignature(byte[] dataToSign)
{
- if (!File.Exists(KeyFilePath))
- throw new Exception("key file path does not exist.");
+ if (!File.Exists(KeyFilePath) && string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
var keyStr = KeyString;
const string ecKeyHeader = "-----BEGIN EC PRIVATE KEY-----";
@@ -446,6 +451,11 @@ namespace Org.OpenAPITools.Client
private RSACryptoServiceProvider GetRSAProviderFromPemFile(string keyString, SecureString keyPassPhrase = null)
{
+ if (string.IsNullOrEmpty(KeyString))
+ {
+ throw new Exception("No API key has been provided.");
+ }
+
const string pempubheader = "-----BEGIN PUBLIC KEY-----";
const string pempubfooter = "-----END PUBLIC KEY-----";
bool isPrivateKeyFile = true;