Пример #1
0
        public void ShowCaseTestSymmetric()
        {
            Assert.IsTrue(maLo.IsValid()); // as the encryption relies on serializing the BO invalid BOs cannot be encrypted.

            byte[]          sharedSecret = Sodium.SecretBox.GenerateKey();
            EncryptedObject encryptedBo;

            using (var encrypter = new SymmetricEncrypter(sharedSecret))
            {
                encryptedBo = encrypter.Encrypt(maLo, "test case");
            }
            Debug.Write(JsonConvert.SerializeObject(encryptedBo, new StringEnumConverter()));
            //{
            //  "boTyp": "ENCRYPTEDOBJECTAEAD",
            //  "versionStruktur": 1,
            //  "AssociatedData": "test case",
            //  "encryptionScheme": "SodiumSymmetricAEAD",
            //  "nonce": "hTbQKm/hAwY=",
            //  "cipherText": "iORhQsADEviVhjDP3d ... fnGfLF+AsL1F"
            //}

            Marktlokation decryptedMaLo;

            using (var decrypter = new SymmetricEncrypter(sharedSecret))
            {
                decryptedMaLo = decrypter.Decrypt <Marktlokation>(encryptedBo);
            }
            Assert.AreEqual(maLo.Lokationsadresse, decryptedMaLo.Lokationsadresse);
        }
Пример #2
0
        public void TestMeLoValidity()
        {
            var malo = new Marktlokation()
            {
                MarktlokationsId = "1235678901",
                Sparte           = Sparte.STROM,
                Energierichtung  = Energierichtung.AUSSP
            };

            Assert.IsFalse(malo.IsValid());              // because the obligatory bilanzierungsmethode is not set
            malo.Bilanzierungsmethode = Bilanzierungsmethode.SLP;
            Assert.IsTrue(malo.IsValid(checkId: false)); // because all obligatory fields are set
            Assert.IsFalse(malo.IsValid());              // but the marklokationsId is wrong
            malo.MarktlokationsId = "51238696781";       // matches the appropriate regex and has the right check sum
            Assert.IsTrue(malo.IsValid());
        }