title: Verify signature generated with RSA 2048-bit key, SHA256 algorithm and PKCSv1.5 padding
body: <p>I have a UWA (Universal Windows Application) signing some data with the <a href="https://msdn.microsoft.com/en-us/library/windows/apps/windows.security.credentials.keycredential.requestsignasync.aspx" rel="nofollow">KeyCredential.RequestSignAsync</a> method.</p>
  
  <p>The signature is created with:</p>
  
  <ul>
  <li>RSA 2048-bit key (public portion can be retrieved with <a href="https://msdn.microsoft.com/en-us/library/windows/apps/windows.security.credentials.keycredential.retrievepublickey.aspx" rel="nofollow">KeyCredential.RetrievePublicKey</a>)</li>
  <li>Hashing algorithm used is SHA256</li>
  <li>Padding used with the signature is PKCSv1.5</li>
  </ul>
  
  <p>And can be validated in the same UWA with the following code:</p>
  
  <pre><code>public static bool VerifySignature(
      IBuffer buffPublicKey,
      IBuffer buffMessageData,
      IBuffer buffSignature)
  {
      bool b = false;
  
      // Open the algorithm provider
      var algProv = AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithmNames.RsaSignPkcs1Sha256);
  
      // Import the public key
      var ckey = algProv.ImportPublicKey(buffPublicKey);
  
      // Verify
      b = CryptographicEngine.VerifySignature(ckey, buffMessageData, buffSignature);
  
      return b;
  }
  </code></pre>
  
  <p>I need to verify that signature but in a regular C# application (not UWA). The Public Key, message and signature are being encoded to base 64 with <strong>CryptographicBuffer.EncodeToBase64String</strong> before being transferred.</p>
  
  <p>So according <strong>System.Security.Cryptography</strong> namespace I tried with:</p>
  
  <pre><code>public static bool VerifySignature(string base64PublicKey, string base64Data, string base64Signature)
  {
      bool b = false;
  
      byte[] publicKey = Convert.FromBase64String(base64PublicKey);
      byte[] data = Convert.FromBase64String(base64Data);
      byte[] signature = Convert.FromBase64String(base64Signature);
  
      using (var rsa = new RSACryptoServiceProvider(2048))
      {
          // Import public key
          rsa.ImportCspBlob(publicKey);
  
          // Create signature verifier with the rsa key
          var signatureDeformatter = new RSAPKCS1SignatureDeformatter(rsa);
  
          // Set the hash algorithm to SHA256.
          signatureDeformatter.SetHashAlgorithm("SHA256");
  
          b = signatureDeformatter.VerifySignature(data, siganture);
      }
  
      return b;
  }
  </code></pre>
  
  <p>But getting a <strong>System.Security.Cryptography.CryptographicException</strong> with <strong>Additional information: Bad Version of provider.</strong>  in:</p>
  
  <blockquote>
    <p>rsa.ImportCspBlob(publicKey);</p>
  </blockquote>
  
  <p><strong>¿How is the proper way to verify the signature with that public key?</strong></p>
  
  <p><strong>EDIT:</strong> Sample values (base64 encoded)</p>
  
  <ul>
  <li>PublicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp6HzbSgZPkJPfZJWydFAKdzUWlQcGHCTZhghg8HwHOfRZp3QZ/iiDORVzdIlW6XYPz76aAn8Nxm/v4NbsQsFPbwIcc7CPOJe21VT+7f6ocZ4kef0dqxUOGuK1FynrqzsAeYoaeTW+w/HElXODOEzZs3CfyE3d4hy3TTM/mVyQGV1FO/hHWB/zXq7ryQ8hXP/ueJimmJvitB7UweemRxvEYfVx52VVAgzg1RqVWeRj8L/obfm0lwQtIAHdDOnIi/cwpsyKQNikjMsf4dFgt14fcOgFdSG06jB840GnOsRZM04CWZQ9ttwAvoNGK/zjriRYGySQ4Ey0K0l5G3UVr56mQIDAQAB</li>
  <li>Data: dGF0b0Bmcm9td2luMzIuY29t</li>
  <li>Signature: lWKRRgWBA2lBAfUvBS+54s9kmHTH3nJwcvYYmjCg5QpWQ9joY7Rzpq0zZjOhyxASXoAN4Vz8+mqSqPWi/4DFH7947ZWZSbopPfxiI7jjDRMAVymG0B+dRVjiMow48ZvhgP/FGSZqeLAei77Z0aAmwN2TBxkClqBpt9uy+nkI7V/TJGAbbLcWfiPWNVOGsU0smoFDQLlJjkocahNSOqjj+9PPFVqbc/VVHQWsSoq1ZxtCPILFwPCCtUCDITXrU/riGMFJ282p/3rfhDJKYis9/izR98/zgBLRoCew8zu8Za4UNWaHaR3HP/6voQI2NiVSKtss1VjvwjwXYIOh56yeSw==</li>
  </ul>