protected internal T Decrypt <T>(ResponseDataInfo output) { T model = default(T); if (output.status_cd != "0") { byte[] decryptREK = EncryptionUtils.AesDecrypt(output.rek, provider.DecryptedKey); byte[] jsonData = EncryptionUtils.AesDecrypt(output.data, decryptREK); string testHmac = EncryptionUtils.GenerateHMAC(jsonData, decryptREK); System.Console.WriteLine("HMAC Match:" + (output.hmac == testHmac)); string base64Payload = UTF8Encoding.UTF8.GetString(jsonData); byte[] decodeJson = Convert.FromBase64String(base64Payload); string finalJson = Encoding.UTF8.GetString(decodeJson); model = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(finalJson); LastJson = finalJson; } return(model); }
protected internal UnsignedDataInfo Encrypt <T>(T input) { UnsignedDataInfo info = new UnsignedDataInfo(); if (input != null) { string finalJson = JsonConvert.SerializeObject(input, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); byte[] encodeJson = UTF8Encoding.UTF8.GetBytes(finalJson); string base64Payload = Convert.ToBase64String(encodeJson); byte[] jsonData = UTF8Encoding.UTF8.GetBytes(base64Payload); info.data = EncryptionUtils.AesEncrypt(jsonData, provider.DecryptedKey); info.hmac = EncryptionUtils.GenerateHMAC(jsonData, provider.DecryptedKey); } return(info); }