コード例 #1
0
        public void ParameterizedTests(
            IEnvelopeEncryption <byte[]> envelopeEncryptionJson,
            Mock <IMetastore <JObject> > metastore,
            KeyState cacheIK,
            KeyState metaIK,
            KeyState cacheSK,
            KeyState metaSK,
            Partition partition)
        {
            using (Session <JObject, byte[]> sessionJsonImpl =
                       new SessionJsonImpl <byte[]>(envelopeEncryptionJson))
            {
                EncryptMetastoreInteractions encryptMetastoreInteractions =
                    new EncryptMetastoreInteractions(cacheIK, metaIK, cacheSK, metaSK);
                DecryptMetastoreInteractions decryptMetastoreInteractions =
                    new DecryptMetastoreInteractions(cacheIK, cacheSK);

                // encrypt with library object(sessionJsonImpl)
                byte[] encryptedPayload = sessionJsonImpl.Encrypt(payload);

                Assert.NotNull(encryptedPayload);
                VerifyEncryptFlow(metastore, encryptMetastoreInteractions, partition);

                metastore.Invocations.Clear();
                JObject decryptedPayload = sessionJsonImpl.Decrypt(encryptedPayload);

                VerifyDecryptFlow(metastore, decryptMetastoreInteractions, partition);
                Assert.True(JToken.DeepEquals(payload, decryptedPayload));
            }
        }
コード例 #2
0
        private void TestDecrypt()
        {
            const string json         = @"{key:'some_key', value:123}";
            JObject      expectedJson = JObject.Parse(json);

            byte[] utf8Bytes = new Asherah.AppEncryption.Util.Json(expectedJson).ToUtf8();

            envelopeEncryptionMock.Setup(x => x.DecryptDataRowRecord(It.IsAny <string>())).Returns(utf8Bytes);

            JObject actualJson = sessionJsonImpl.Decrypt("some data row record");

            Assert.Equal(expectedJson, actualJson);
        }