Click here to Skip to main content
15,886,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to verify signature using RSA 256 Algorithm in asp.net with c#. On verifying the signed Original Message as bytes following issue comes (invalid characters).

Signed original message as below:

1:F01BNZWOMRXAXXX0001000001}{2:I102CBOMOMRUXACHN}{3:{113:0100}}{4:
:20:BNZW0M00017DW
:23:CREDIT
:50K:/00410039933001
SUBAIH NASSER SALIM AL SIYABI
POBOX 644 MUSCAT
MANOOMA - SEEB
,OMAN
:52A:BNZWOMRX
BANK NIZWA
:26T:001
:77B:/DNUM/492282
/DDATE/170423
:71A:SHA
:21:TRF000492282/1
:32B:OMR75,000
:57A:BMUSOMRX
:59:/0301011157980014
FAREEQ AL RAHMA
:70:SO
:32A:170427OMR75,000
:72:/PRT/10
/CODTYPTR/001
-}


What I have tried:

public static bool VerifyData(string originalMessage, string signedMessage, RSAParameters publicKey)
   {
       bool success = false;

       using (var rsa = new RSACryptoServiceProvider())
       {


           byte[] bytesToVerify = Convert.FromBase64String(originalMessage);

           byte[] signedBytes = Convert.FromBase64String(signedMessage);
           try
           {
               rsa.ImportParameters(publicKey);

               SHA512Managed Hash = new SHA512Managed();

               byte[] hashedData = Hash.ComputeHash(signedBytes);

               success = rsa.VerifyData(bytesToVerify, CryptoConfig.MapNameToOID("SHA256"), signedBytes);
           }
           catch (CryptographicException e)
           {
               Console.WriteLine(e.Message);
           }
           finally
           {
               rsa.PersistKeyInCsp = false;
           }
       }
       return success;
   }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900