Пример #1
0
        public void VerifyData_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>())
            {
                signedMessage = rsacsp.SignData<SHA256Cng>(message);
                nativeXmlString = rsacsp.ToXmlString(true);
            }

            using (var cipher = new RSACipher<RSACryptoServiceProvider>(nativeXmlString))
            {
                isMessageNotTamperedWith = cipher.VerifyData<SHA256Cng>(message, signedMessage);
            }

            Assert.IsTrue(isMessageNotTamperedWith);
        }
Пример #2
0
        public void SignData_CompareSignaturesOfRSACSPAndRSACipher_Pass()
        {
            int wantedKeySize = 4096;
            Random rdm = new Random();
            byte[] message = new byte[256];
            byte[] signedMessage;
            byte[] signedMessageNative;
            string nativeXmlString;
            rdm.NextBytes(message);

            using(var rsacsp = new RSACryptoServiceProvider(wantedKeySize))
            {
                signedMessageNative = rsacsp.SignData(message, new SHA512Managed());
                nativeXmlString = rsacsp.ToXmlString(true);
            }

            using (var cipher = new RSACipher<RSACryptoServiceProvider>(nativeXmlString))
            {
                signedMessage = cipher.SignData<SHA512Managed>(message);
            }

            CollectionAssert.AreEqual(signedMessage, signedMessageNative);
        }