title: Problems to write a byte array of a signed hash with a private key in a text file and get it back as the same format
body: <p>I'm writing a bytes array to a text file of a signed hash, that I first convert to a base64 string and convert to a bytes array again with the encoding UTF-8 before writing to the text file, my current problem is that when I get the bytes back I don't know how to convert to the original format to validate my signed hash with the public key, does anybody know to convert it back?</p>
  <p>This is how I convert my original bytes to be able to write in the text file:</p>
  <pre><code>        public static byte[] ConvertToBase64(byte[] bytes)
          {
              string base64 = Convert.ToBase64String(bytes);
              return Encoding.UTF8.GetBytes(base64);
          }
  </code></pre>
  <p>This is how I sign the hash:</p>
  <pre><code>        private byte[] signData(byte[] dataValue)
          {
              X509Certificate2 privateKey = new X509Certificate2(privateKeyfileName, password);
  
              //Encryting/Signing a hash
              using (ECDsa ecdsa = privateKey.GetECDsaPrivateKey())
              {
                  if (ecdsa == null) throw new Exception(&quot;Not an ECDSA cert, or has no private key&quot;);
  
                  return ecdsa.SignData(dataValue, HashAlgorithmName.SHA256);
              }
          }
  </code></pre>
  <p>This is how I create the hash:</p>
  <pre><code>        // The cryptographic service provider.
          private SHA256 Sha256 = SHA256.Create();
  
          // Compute the file's hash.
          private byte[] GetHashSha256FromFile(string filename)
          {
              using (FileStream stream = File.OpenRead(filename))
              {
                  return Sha256.ComputeHash(stream);
              }
          }
  </code></pre>
  <p>This is how I was supposed to validate the signed hash if I could get the value from my original signed hash:</p>
  <pre><code>        private bool verifyData(byte[] dataValue, byte[] dataSigned)
          {
              byte[] mycertCer = Properties.Resources.mycertCer;
              X509Certificate2 publicKey = new X509Certificate2(mycertCer, password);
  
              //Checking the hash and signature
              using (ECDsa ecdsa = publicKey.GetECDsaPublicKey())
              {
                  if (ecdsa == null) throw new Exception(&quot;Not an ECDSA cert, or has no private key&quot;);
  
                  return ecdsa.VerifyData(dataValue, dataSigned, HashAlgorithmName.SHA256);
              }
          }
  </code></pre>
  <p>I'll appreciate any help, let me know if you need more details.</p>