예제 #1
0
        public void TestBasicSigningAndVerification()
        {
            var encryptionManager = new EncryptionManager(new KeyStore(new KeyStoreRepository(new DataContext())));
            var hashManager       = new HashManager();

            var cryptoService        = new CryptographyService.CryptographyService(encryptionManager, hashManager);
            var wrappedCryptoService = new CryptoServiceWrapper <FabricSigning>(cryptoService, null);

            var signingContent = GenerateSampleFabricSignContent();
            var signingOutcome = wrappedCryptoService.SignContent(signingContent);

            var signature = new DigitalSignature <FabricSigning>()
            {
                OriginalContent    = signingContent,
                SignedContent      = signingOutcome.Signature,
                SignatoryReference = signingOutcome.SignatoryReference
            };

            var signOutcome = wrappedCryptoService.VerifySignature(signature);

            Assert.IsTrue(signOutcome.SignatoryMatchedToSignature);
            Assert.IsTrue(signOutcome.SignedContentMatchesToSignature);

            // This represents application side verification of signed content. Helpful to identify what in content has changed
            Assert.IsTrue(signOutcome.ExpectedContent?.Agreements?.FirstOrDefault().Description == signOutcome.SignedContent?.Agreements?.FirstOrDefault().Description);
        }
예제 #2
0
        public void EncryptAndDecryptContentTest()
        {
            var encryptionManager = new EncryptionManager(new KeyStore(new KeyStoreRepository(new DataContext())));
            var hashManager       = new HashManager();

            var cryptoService        = new CryptographyService.CryptographyService(encryptionManager, hashManager);
            var wrappedCryptoService = new CryptoServiceWrapper <string>(cryptoService, null);

            const string myContent = "Sample text to encrypt";
            var          salt      = Guid.NewGuid();

            var encryptedOutcome = wrappedCryptoService.Encrypt(myContent, salt.ToString());
            var decryptedOutcome = wrappedCryptoService.Decrypt(encryptedOutcome, salt.ToString());

            Assert.IsTrue(myContent == decryptedOutcome);
        }