Ejemplo n.º 1
0
 public static bool VerifySignature(DataSignature ds)
 {
     byte[] remoteText = ds.Data;
     byte[] signHash   = ds.Signature;
     if (dsa == null)
     {
         dsa = new DSACryptoServiceProvider();
     }
     if (ds.PublicKey != null)
     {
         try
         {
             dsa.FromXmlString(ds.PublicKey);
             return(dsa.VerifyData(remoteText, signHash));
         }
         catch
         {
             return(false);
         }
     }
     else
     {
         return(true);
     }
 }
Ejemplo n.º 2
0
        public static DataSignature CreateSignature(byte[] plainText)
        {
            DataSignature ds = new DataSignature();

            if (plainText != null)
            {
                SHA1Managed sha1 = new SHA1Managed();
                //if (dsa == null)
                dsa = new DSACryptoServiceProvider();
                DSASignatureFormatter formatter = new DSASignatureFormatter(dsa);
                byte[] data = plainText;
                byte[] hash = sha1.ComputeHash(data);
                formatter.SetHashAlgorithm("SHA1");
                byte[] signHash = formatter.CreateSignature(hash);
                ds.Data      = data;
                ds.Signature = signHash;
                ds.PublicKey = dsa.ToXmlString(false);
            }
            return(ds);
        }