locked
How to verify specified signature data using RSACryptoServiceProvider VerifyData RRS feed

  • Question

  • I want to verify the sign data encrypted in other than .NET language using RSA algorithm. I have public key, data and sign signauter bellow the code which I write to verify data but VerifyData always return FALSE kinldy point out what is wrong in my code.

     

    private RSACryptoServiceProvider rsa;

    protected void Page_Load(object sender, EventArgs e)

        {

                string SignedToken = Request.QueryString["Token" ];

                string SignedToken = Encoding .ASCII.GetString(Convert .FromBase64String(SignedToken));

                 string PlainText = Request.QueryString[" PlainText" ];

                AssignParameter();

                ReadPublicKey();

                SHA1Managed sha = new SHA1Managed ();

                Byte [] PlainTextByte = Encoding .UTF8.GetBytes(PlainText);

                Byte [] Signature = Encoding .UTF8.GetBytes(SignedToken);

               

                if (rsa.VerifyData(PlainTextByte,sha, Signature))

                {

                    Response.Write(“Verified ”);               

                }

                else

                {

                    Response.Write ("Not Verified" );

                   

                }

    }

     

     

    public   void AssignParameter()

        {

     

            const int PROVIDER_RSA_FULL = 1;

            const string CONTAINER_NAME = "TestCont" ;

            CspParameters cspParams;

            cspParams = new CspParameters (PROVIDER_RSA_FULL);

            cspParams.KeyContainerName = CONTAINER_NAME;

             cspParams.Flags = CspProviderFlags . UseDefaultKeyContainer;

            cspParams.ProviderName = "Microsoft Strong Cryptographic Provider" ;

            rsa = new RSACryptoServiceProvider (cspParams);

            

        }

        private void ReadPublicKey()

        {

     

            StreamReader reader = new StreamReader (@"C:\PublicKey.xml" );

            string publicOnlyKeyXML = reader.ReadToEnd();

             rsa.FromXmlString(publicOnlyKeyXML);

            reader.Close();

           

        }

     


    Imran
    Wednesday, July 22, 2009 4:45 PM