title: Getting an error when trying to convert a string to base64 for HMACSHA1 .NET
body: <p>I am trying to generate a signature and sign it using HMACSHA1. I keep getting an error saying that the input is not a valid Base-64 string.</p>
  <p>Here is the code</p>
  <pre><code>string authSecret = &quot;dBV2PdhYMnruSMb&quot;;
  string signSession = &quot;application_id=1234&amp;auth_key=aDRceQyTXSYEdJU&amp;nonce=4567779998&amp;timestamp=1623103648&amp;user[login]=johnWick@mail.com&amp;user[password]=12345678&quot;;
  
  //convert the session signature string to a byte array
  byte[] signature = Encoding.UTF8.GetBytes(signSession);
  
  // converting authsecret to a byte array
  var apiKey = Convert.FromBase64String(authSecret);
  
  // Generate a HMACSHA1 signature
  using(HMACSHA1 hmac = new HMACSHA1(apiKey))
  {
      byte[] signatureBytes = hmac.ComputeHash(signature);
      string base64Signature = Convert.ToBase64String(signatureBytes);
      session.Signature = base64Signature;
  }
  </code></pre>
  <pre class="lang-cs prettyprint-override"><code>// this is the line that keeps throwing an error
  var apiKey = Convert.FromBase64String(authSecret);
  </code></pre>
  <p>And here is the error message</p>
  <pre><code>System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
     at System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength)
     at System.Convert.FromBase64String(String s)
     at ChatboxApi.Utilities.ConnectyCubeUtils.GenerateSessionParams(User user) in C:\Users\Owner\Documents\App Projects\React_Projects\chatboxApi\ChatboxApi\Utilities\ConnectyCubeUtils.cs:line 110
     at ChatboxApi.Services.AuthService.AuthService.CreateSession(User user) in C:\Users\Owner\Documents\App Projects\React_Projects\chatboxApi\ChatboxApi\Services\AuthService\AuthService.cs:line 17
     at ChatboxApi.Controllers.AuthController.SignUp(User user) in C:\Users\Owner\Documents\App Projects\React_Projects\chatboxApi\ChatboxApi\Controllers\AuthController.cs:line 22
     at lambda_method6(Closure , Object )
     at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
     at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.&lt;InvokeActionMethodAsync&gt;g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
     at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.&lt;InvokeNextActionFilterAsync&gt;g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
     at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
     at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)
     at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.&lt;InvokeInnerFilterAsync&gt;g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
     at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeFilterPipelineAsync&gt;g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
     at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeAsync&gt;g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
     at Microsoft.AspNetCore.Routing.EndpointMiddleware.&lt;Invoke&gt;g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
     at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
     at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
     at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
     at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
  </code></pre>