public void ParameterizedTests( IEnvelopeEncryption <byte[]> envelopeEncryptionJson, Mock <IMetastorePersistence <JObject> > metastorePersistence, KeyState cacheIK, KeyState metaIK, KeyState cacheSK, KeyState metaSK, AppEncryptionPartition appEncryptionPartition) { using (AppEncryption <JObject, byte[]> appEncryptionJsonImpl = new AppEncryptionJsonImpl <byte[]>(envelopeEncryptionJson)) { EncryptMetastoreInteractions encryptMetastoreInteractions = new EncryptMetastoreInteractions(cacheIK, metaIK, cacheSK, metaSK); DecryptMetastoreInteractions decryptMetastoreInteractions = new DecryptMetastoreInteractions(cacheIK, cacheSK); // encrypt with library object(appEncryptionJsonImpl) byte[] encryptedPayload = appEncryptionJsonImpl.Encrypt(payload); Assert.NotNull(encryptedPayload); VerifyEncryptFlow(metastorePersistence, encryptMetastoreInteractions, appEncryptionPartition); metastorePersistence.Invocations.Clear(); JObject decryptedPayload = appEncryptionJsonImpl.Decrypt(encryptedPayload); VerifyDecryptFlow(metastorePersistence, decryptMetastoreInteractions, appEncryptionPartition); Assert.True(JToken.DeepEquals(payload, decryptedPayload)); } }
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 = appEncryptionJsonImpl.Decrypt("some data row record"); Assert.Equal(expectedJson, actualJson); }