Ejemplo n.º 1
0
        public void When_Cipher_Is_Modified_HMAC_Throws_AuthException()
        {
            var providers = new Dictionary <string, ICryptoProvider>
            {
                { "AES-256-HMAC-SHA256", new AesCryptoProvider(new InsecureKeyStore("thekeyname", "!mysecretkey#9^5"))
                  {
                      KeyName        = "thekeyname",
                      PrivateKeyName = "123teuwoeiwkwkey"
                  } }
            };
            var serializer = new EncryptedFieldSerializer(
                new JsonSerializerSettings {
                ContractResolver = new FieldEncryptorContractResolver(providers)
            },
                new JsonSerializerSettings {
                ContractResolver = new FieldEncryptorContractResolver(providers)
            });

            var poco = new Poco
            {
                StringField = "Woot!"
            };

            var bytes = serializer.Serialize(poco);

            bytes[90] = Convert.FromBase64String(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("s")))[0];

            Assert.Throws <AuthenticationException>(() => serializer.Deserialize <Poco>(bytes, 0, bytes.Length));
        }
Ejemplo n.º 2
0
        public void Test_Serialize()
        {
            var providers = new Dictionary <string, ICryptoProvider>
            {
                { "AES-256-HMAC-SHA256", new AesCryptoProvider(new InsecureKeyStore("thekeyname", "!mysecretkey#9^5"))
                  {
                      KeyName        = "thekeyname",
                      PrivateKeyName = "123teuwoeiwkwkey"
                  } }
            };
            var serializer = new EncryptedFieldSerializer(
                new JsonSerializerSettings {
                ContractResolver = new FieldEncryptorContractResolver(providers)
            },
                new JsonSerializerSettings {
                ContractResolver = new FieldEncryptorContractResolver(providers)
            });

            var poco = new Poco
            {
                StringField = "Woot!"
            };
            var bytes = serializer.Serialize(poco);
            var poco2 = serializer.Deserialize <Poco>(bytes, 0, bytes.Length);

            Assert.Equal(poco.StringField, poco2.StringField);
        }