Ejemplo n.º 1
0
        public void SetUp()
        {
            var certificate = TestCertificates.GetCertificate();

            // Отправитель имеет открытый асимметричный ключ для шифрации сессионного ключа
            _publicKey = certificate.GetPublicKeyAlgorithm();

            // Получатель имеет закрытый асимметричный ключ для дешифрации сессионного ключа
            _privateKey = certificate.GetPrivateKeyAlgorithm();
        }
Ejemplo n.º 2
0
        public void ShouldSignXml()
        {
            // Given
            var signingCertificate = TestCertificates.GetCertificate();
            var xmlDocument        = CreateXmlDocument();

            // When
            var signedXmlDocument = SignXmlDocument(xmlDocument, signingCertificate);

            // Then
            Assert.IsTrue(VerifyXmlDocumentSignature(signedXmlDocument));
        }
Ejemplo n.º 3
0
        public void ShouldSignXml()
        {
            // Given
            var signingCertificate = TestCertificates.GetCertificate();
            var smevRequest        = CreateSmevRequest();

            // When
            var signedXmlDocument = SignSmevRequest(smevRequest, signingCertificate);

            // Then
            Assert.IsTrue(VerifySmevRequestSignature(signedXmlDocument));
        }
Ejemplo n.º 4
0
        public void ShouldSign()
        {
            // Given
            var certificate = TestCertificates.GetCertificate();
            var message     = CreateMessage();

            // When
            var detachedSignature        = SignMessage(certificate, message);
            var isValudDetachedSignature = VerifyMessage(message, detachedSignature);

            // Then
            Assert.IsTrue(isValudDetachedSignature);
        }
Ejemplo n.º 5
0
        public void ShouldEncryptAndDecrypt()
        {
            // Given
            var certificate = TestCertificates.GetCertificate();
            var message     = CreateMessage();

            // When
            var encryptedMessage = EncryptMessage(certificate, message);
            var decryptedMessage = DecryptMessage(encryptedMessage);

            // Then
            Assert.IsTrue(message.SequenceEqual(decryptedMessage));
        }
Ejemplo n.º 6
0
        public void ShouldSign()
        {
            // Given
            var certificate = TestCertificates.GetCertificate();
            var message     = CreateMessage();

            // When
            var signedMessage        = SignMessage(certificate, message);
            var isValudSignedMessage = VerifyMessage(signedMessage);

            // Then
            Assert.IsTrue(isValudSignedMessage);
        }
Ejemplo n.º 7
0
        public void ShouldEncryptXml()
        {
            // Given
            var certificate = TestCertificates.GetCertificate();
            var xmlDocument = CreateXmlDocument();
            var expectedXml = xmlDocument.OuterXml;

            // When
            var encryptedXmlDocument = EncryptXmlDocument(xmlDocument, certificate);
            var decryptedXmlDocument = DecryptXmlDocument(encryptedXmlDocument);
            var actualXml            = decryptedXmlDocument.OuterXml;

            // Then
            Assert.AreEqual(expectedXml, actualXml);
        }
Ejemplo n.º 8
0
        public void ShouldSignDataStream()
        {
            // Given
            var certificate = TestCertificates.GetCertificate();
            var privateKey  = (Gost3410AsymmetricAlgorithmBase)certificate.GetPrivateKeyAlgorithm();
            var publicKey   = (Gost3410AsymmetricAlgorithmBase)certificate.GetPrivateKeyAlgorithm();
            var dataStream  = CreateDataStream();

            // When

            dataStream.Seek(0, SeekOrigin.Begin);
            var signature = CreateSignature(privateKey, dataStream);

            dataStream.Seek(0, SeekOrigin.Begin);
            var isValidSignature = VerifySignature(publicKey, dataStream, signature);

            // Then
            Assert.IsTrue(isValidSignature);
        }
        public void ShouldSign()
        {
            // Given
            var certificate = TestCertificates.GetCertificate();

            Assert.IsNotNull(certificate);
            Assert.AreEqual(certificate.SignatureAlgorithm.Value, "1.2.643.2.2.3");
            var message = CreateMessage();

            // When
            var signedMessage = SignMessage(certificate, message);
            var bFile         = Convert.ToBase64String(signedMessage);

            File.WriteAllBytes("test.txt", signedMessage);
            var isValudSignedMessage = VerifyMessage(signedMessage);

            // Then
            Assert.IsTrue(isValudSignedMessage);
        }