Пример #1
0
        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);
        }
Пример #2
0
        public static CipherText ToEncryptedText(string plainText, string bulkCipherKey)
        {
            var        results = Resources.ScriptEngine.Evaluate(string.Format("sjcl.encrypt(\"{0}\",\"{1}\")", bulkCipherKey, plainText));
            CipherText cipherText;

            if (CipherText.TryParse(results.ToString(), out cipherText))
            {
                return(cipherText);
            }

            return(null);
        }
Пример #3
0
        public byte[] Execute(byte[] arg)
        {
            var        cipherTextString = Encoding.UTF8.GetString(arg);
            CipherText cipherText;

            if (!CipherText.TryParse(cipherTextString, out cipherText))
            {
                throw new ArgumentException(string.Format("the cipher text could not be parsed \n '{0}'", cipherTextString));
            }

            var plainText = NoFuture.Encryption.Sjcl.BulkCipherKey.ToPlainText(cipherText, _bulkCipherKey);

            return(Encoding.UTF8.GetBytes(plainText));
        }
Пример #4
0
        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);
        }