RSA-SHA256 fails to verify?

Nov 19, 2008 at 7:40 PM

Why does this not verify?

            #region Create temp private key for this test
            CspParameters parameters = new CspParameters();
            parameters.Flags = CspProviderFlags.UseMachineKeyStore;
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(768, parameters);
            RSAParameters privateKey = rsa.ExportParameters(true);
            #endregion

            byte[] data = new byte[] { 0, 1, 2, 3, 4, 5 };
            byte[] signature;

            using (RSAManaged rsaSHA256 = new RSAManaged(privateKey))
            {
                //Microsoft.Cryptography.RSAPKCS1SHA256SignatureDescription r = new Microsoft.Cryptography.RSAPKCS1SHA256SignatureDescription();
                //signature = r.CreateFormatter(AsymmetricAlgorithm.Create("RSABase")).CreateSignature(data);
                //Console.WriteLine("Passed");
                signature = rsaSHA256.SignData(data, new SHA256Managed());
                if (rsaSHA256.VerifyData(data, new SHA256Managed(), signature))
                {
                    Console.WriteLine("RSA-SHA256 signature verified");
                }
                else
                {
                    Console.WriteLine("RSA-SHA256 signature failed to verify");
                }
            }

Dec 5, 2008 at 4:34 AM
Anybody?