Пример #1
0
        public void SignHash_VerifiesComputedSignature_Pass()
        {
            Random rdm = new Random();
            byte[] message = new byte[256];
            byte[] signedMessage;
            string nativeXmlString;
            bool isMessageNotTamperedWith = true;
            rdm.NextBytes(message);

            using (var rsacsp = new RSACipher<RSACryptoServiceProvider>())
            {
                byte[] firstHash = new SHA256Managed().ComputeHash(message);
                signedMessage = rsacsp.SignHash(firstHash);
                nativeXmlString = rsacsp.ToXmlString(true);
            }

            using (var cipher = new RSACipher<RSACryptoServiceProvider>(nativeXmlString))
            {
                byte[] n = new SHA256Managed().ComputeHash(message);
                isMessageNotTamperedWith = cipher.VerifyHash(n, signedMessage);
            }

            Assert.IsTrue(isMessageNotTamperedWith);
        }