public void TestTryParse() { var testValues = new CipherText { adata = "atada", cipher = "rehpic", ct = "tc", iter = 1000, iv = "vi", ks = 1000, mode = "edom", v = 1, salt = "tlas", ts = 1 }; var toStringBuilder = new StringBuilder(); toStringBuilder.Append("{"); toStringBuilder.Append(string.Format("\"adata\":\"{0}\",", testValues.adata)); toStringBuilder.Append(string.Format("\"cipher\":\"{0}\",", testValues.cipher)); toStringBuilder.Append(string.Format("\"iter\":{0},", testValues.iter)); toStringBuilder.Append(string.Format("\"iv\":\"{0}\",", testValues.iv)); toStringBuilder.Append(string.Format("\"ks\":{0},", testValues.ks)); toStringBuilder.Append(string.Format("\"mode\":\"{0}\",", testValues.mode)); toStringBuilder.Append(string.Format("\"v\":{0},", testValues.v)); toStringBuilder.Append(string.Format("\"salt\":\"{0}\",", testValues.salt)); toStringBuilder.Append(string.Format("\"ts\":{0},", testValues.ts)); toStringBuilder.Append(string.Format("\"ct\":\"{0}\"", testValues.ct)); toStringBuilder.Append("}"); CipherText testSubject; var testResult =CipherText.TryParse(toStringBuilder.ToString(), out testSubject); Assert.IsTrue(testResult); }
public void TestToString() { var testSubject = new CipherText { adata = "atada", cipher = "rehpic", ct = "tc", iter = 1000, iv = "vi", ks = 1000, mode = "edom", v = 1, salt = "tlas", ts =1 }; var testResult = testSubject.ToString(); Assert.IsNotNull(testResult); Assert.IsFalse(String.IsNullOrWhiteSpace(testResult)); Assert.IsTrue(testResult.Contains(string.Format("\"adata\":\"{0}\"", testSubject.adata))); Assert.IsTrue(testResult.Contains(string.Format("\"cipher\":\"{0}\"", testSubject.cipher))); Assert.IsTrue(testResult.Contains(string.Format("\"ct\":\"{0}\"", testSubject.ct))); Assert.IsTrue(testResult.Contains(string.Format("\"iter\":{0}", testSubject.iter))); Assert.IsTrue(testResult.Contains(string.Format("\"iv\":\"{0}\"", testSubject.iv))); Assert.IsTrue(testResult.Contains(string.Format("\"ks\":{0}", testSubject.ks))); Assert.IsTrue(testResult.Contains(string.Format("\"mode\":\"{0}\"", testSubject.mode))); Assert.IsTrue(testResult.Contains(string.Format("\"v\":{0}", testSubject.v))); Assert.IsTrue(testResult.Contains(string.Format("\"salt\":\"{0}\"", testSubject.salt))); Assert.IsTrue(testResult.Contains(string.Format("\"ts\":{0}", testSubject.ts))); }
public static string ToPlainText(CipherText encryptedData, string bulkCipherKey) { //js and C# string escape seq's are the same... var results = Resources.ScriptEngine.Evaluate(string.Format("sjcl.decrypt(\"{0}\", \"{1}\" )", bulkCipherKey, encryptedData.ToString().Replace("\"", "\\\""))); return results.ToString(); }
/// <summary> /// Given a string as JSON the method attempt to parse the /// string into <see cref="CipherText"/>. /// </summary> /// <param name="sjclJson">The JSON string</param> /// <param name="parseResult">The object reference which will recieve the data upon a successful parse.</param> /// <returns>True if string parsed, false otherwise.</returns> public static bool TryParse(string sjclJson, out CipherText parseResult) { try { var data = Encoding.UTF8.GetBytes(sjclJson); var jsonSerializer = new DataContractJsonSerializer(typeof(CipherText)); using (var ms = new MemoryStream(data)) { parseResult = (CipherText)jsonSerializer.ReadObject(ms); return(true); } } catch { parseResult = null; return(false); } }
/// <summary> /// Given a string as JSON the method attempt to parse the /// string into <see cref="CipherText"/>. /// </summary> /// <param name="sjclJson">The JSON string</param> /// <param name="parseResult">The object reference which will recieve the data upon a successful parse.</param> /// <returns>True if string parsed, false otherwise.</returns> public static bool TryParse(string sjclJson, out CipherText parseResult) { try { var data = Encoding.UTF8.GetBytes(sjclJson); var jsonSerializer = new DataContractJsonSerializer(typeof(CipherText)); using (var ms = new MemoryStream(data)) { parseResult = (CipherText)jsonSerializer.ReadObject(ms); return true; } } catch { parseResult = null; return false; } }
public void TestToPlainTextWithEscCharInData() { var pk = "5cK+?XLr_Gc0Rt@0bYW$7JMpTmj"; var test_input = new NoFuture.Shared.CipherText { adata = string.Empty, cipher = "aes", ct = "praRbuuVATkwyxDMjZhiACQaLupW3Jsde78=", iter = 1000, iv = "DF4D2nAa6WZT6qYMojq2YQ==", ks = 128, mode = "ccm", salt = @"M9egkIg2Y\/Q=", ts = 64, v = 1 }; Console.WriteLine(test_input.ToString()); var testResult = NoFuture.Encryption.Sjcl.BulkCipherKey.ToPlainText(test_input, pk); }
public void TestToPlainTextWithEscCharInData() { var pk = "5cK+?XLr_Gc0Rt@0bYW$7JMpTmj"; var test_input = new NoFuture.Shared.CipherText { adata = string.Empty, cipher = "aes", ct = "praRbuuVATkwyxDMjZhiACQaLupW3Jsde78=", iter = 1000, iv = "DF4D2nAa6WZT6qYMojq2YQ==", ks = 128, mode = "ccm", salt = @"M9egkIg2Y\/Q=", ts = 64, v = 1 }; Console.WriteLine(test_input.ToString()); var testResult = NoFuture.Encryption.Sjcl.BulkCipherKey.ToPlainText(test_input, pk); Assert.IsNotNull(testResult); }
public void ToggleStringJson() { var testValues = new CipherText { adata = "atada", cipher = "rehpic", ct = "tc", iter = 1000, iv = "vi", ks = 1000, mode = "edom", v = 1, salt = "tlas", ts = 1 }; CipherText testSubject; var testResultTryParse = CipherText.TryParse(testValues.ToString(), out testSubject); Assert.IsTrue(testResultTryParse); }