Example #1
0
        //[ExpectedException (typeof(ArgumentNullException))]
        public void TestNullEncryption()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            //serialized string
            string message = null;
            //encrypt

            var ex = Assert.Throws <ArgumentNullException>(() => pubnubCrypto.Encrypt(message)); // True (("").Equals (encrypted));

            Assert.That(ex.Message.Contains("Argument cannot be null."), ex.Message, null);
        }
Example #2
0
        public void TestUnicodeCharsEncryptionJSONFx()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
            string       message      = "漢語";

            message = Common.SerializeUsingJSONFx(message);
            Console.WriteLine(message);
            string encrypted = pubnubCrypto.Encrypt(message);

            Console.WriteLine(encrypted);
            Assert.AreEqual("+BY5/miAA8aeuhVl4d13Kg==", encrypted);
        }
Example #3
0
        public void TestMyObjectEncryption()
        {
            PubnubCrypto pc = new PubnubCrypto("enigma");
            //create an object of the custom class
            CustomClass cc = new CustomClass();
            //serialize it
            string result = JsonConvert.SerializeObject(cc);
            //encrypt it
            string encryptedMessage = pc.Encrypt(result);

            Assert.AreEqual("Zbr7pEF/GFGKj1rOstp0tWzA4nwJXEfj+ezLtAr8qqE=", encryptedMessage);
        }
Example #4
0
        public void TestNullEncryption()
        {
            Assert.Throws <ArgumentNullException>(() =>
            {
                PubnubCrypto pc = new PubnubCrypto("enigma");
                //serialized string
                string message = null;

                //encrypt
                string encryptedMessage = pc.Encrypt(message);
            });
        }
Example #5
0
        public void TestMyObjectEncryptionJSONFx()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
            //create an object of the custom class
            CustomClass cc = new CustomClass();
            //serialize it
            string result = Common.SerializeUsingJSONFx(cc);
            //encrypt it
            string encrypted = pubnubCrypto.Encrypt(result);

            Assert.AreEqual("Zbr7pEF/GFGKj1rOstp0tWzA4nwJXEfj+ezLtAr8qqE=", encrypted);
        }
Example #6
0
        public void TestGermanCharsEncryption()
        {
            PubnubCrypto pc      = new PubnubCrypto("enigma");
            string       message = "ÜÖ";

            message = JsonConvert.SerializeObject(message);
            Console.WriteLine(message);
            string encryptedMessage = pc.Encrypt(message);

            Console.WriteLine(encryptedMessage);
            Assert.AreEqual("stpgsG1DZZxb44J7mFNSzg==", encryptedMessage);
        }
Example #7
0
        public void TestObjectEncryption()
        {
            PubnubCrypto pc = new PubnubCrypto("enigma");
            //create an object
            Object obj = new Object();
            //serialize
            string serializedObject = JsonConvert.SerializeObject(obj);
            //encrypt
            string encryptedMessage = pc.Encrypt(serializedObject);

            Assert.That("IDjZE9BHSjcX67RddfCYYg==" == encryptedMessage);
        }
Example #8
0
        public void TestArrayEncryption()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");

            //create an empty array object
            object [] objArr = {};
            string    strArr = JsonConvert.SerializeObject(objArr);
            //Encrypt
            string encrypted = pubnubCrypto.Encrypt(strArr);

            Assert.AreEqual("Ns4TB41JjT2NCXaGLWSPAQ==", encrypted);
        }
Example #9
0
        public void TestUnicodeCharsEncryption()
        {
            PubnubCrypto pc      = new PubnubCrypto("enigma");
            string       message = "漢語";

            message = JsonConvert.SerializeObject(message);
            Console.WriteLine(message);
            string encryptedMessage = pc.Encrypt(message);

            Console.WriteLine(encryptedMessage);
            Assert.AreEqual("+BY5/miAA8aeuhVl4d13Kg==", encryptedMessage);
        }
Example #10
0
        public void TestObjectEncryption()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
            //create an object
            Object obj = new Object();
            //serialize
            string strObj = JsonConvert.SerializeObject(obj);
            //encrypt
            string encrypted = pubnubCrypto.Encrypt(strObj);

            Assert.AreEqual("IDjZE9BHSjcX67RddfCYYg==", encrypted);
        }
Example #11
0
        public void TestGermanCharsEncryption()
        {
            Debug.Log("Running TestGermanCharsEncryption()");
            PubnubCrypto pc      = new PubnubCrypto("enigma");
            string       message = "ÜÖ";

            string serializedMessage = (new JsonFXDotNet().SerializeToJsonString(message)).ToString(); //JsonConvert.SerializeObject(message);

            string encryptedMessage = pc.Encrypt(serializedMessage);

            UUnitAssert.Equals("stpgsG1DZZxb44J7mFNSzg==", encryptedMessage);
        }
Example #12
0
        public void TestUnicodeCharsEncryption()
        {
            Debug.Log("Running TestUnicodeCharsEncryption()");
            PubnubCrypto pc      = new PubnubCrypto("enigma");
            string       message = "漢語";

            message = new JsonFXDotNet().SerializeToJsonString(message); //JsonConvert.SerializeObject(message);

            string encryptedMessage = pc.Encrypt(message);

            UUnitAssert.Equals("+BY5/miAA8aeuhVl4d13Kg==", encryptedMessage);
        }
Example #13
0
        public void TestPubNubEncryption1JSONFX()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
            //non serialized string
            string message = "Pubnub Messaging API 1";

            //serialize
            message = Common.SerializeUsingJSONFx(message);
            //encrypt
            string encrypted = pubnubCrypto.Encrypt(message);

            Assert.AreEqual("f42pIQcWZ9zbTbH8cyLwByD/GsviOE0vcREIEVPARR0=", encrypted);
        }
Example #14
0
        public void TestPubNubEncryption2JSONFx()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
            //Deserialized
            string message = "Pubnub Messaging API 2";

            //serialize the message
            message = Common.SerializeUsingJSONFx(message);
            //encrypt
            string encrypted = pubnubCrypto.Encrypt(message);

            Assert.AreEqual("f42pIQcWZ9zbTbH8cyLwB/tdvRxjFLOYcBNMVKeHS54=", encrypted);
        }
Example #15
0
        //will fail with minijson
        //[Test]
        public void TestObjectEncryptionMiniJson()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            //create an object
            Object obj = new Object();
            //serialize
            string strObj = Common.SerializeMiniJson(obj);
            //encrypt
            string encrypted = pubnubCrypto.Encrypt(strObj);

            Assert.True(("IDjZE9BHSjcX67RddfCYYg==").Equals(encrypted));
        }
Example #16
0
        public void TestArrayEncryptionMiniJson()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);

            //create an empty array object
            object[] objArr = { };
            string   strArr = Common.SerializeMiniJson(objArr);
            //Encrypt
            string encrypted = pubnubCrypto.Encrypt(strArr);

            Assert.True(("Ns4TB41JjT2NCXaGLWSPAQ==").Equals(encrypted));
        }
Example #17
0
        public void TestGermanCharsEncryptionJSONFx()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
            string       message      = "ÜÖ";

            message = Common.SerializeUsingJSONFx(message);
            Console.WriteLine(message);
            string encrypted = pubnubCrypto.Encrypt(message);

            Console.WriteLine(encrypted);

            Assert.AreEqual("stpgsG1DZZxb44J7mFNSzg==", encrypted);
        }
Example #18
0
        public void TestMyObjectEncryption()
        {
            Debug.Log("Running TestMyObjectEncryption()");
            PubnubCrypto pc = new PubnubCrypto("enigma");
            //create an object of the custom class
            CustomClass cc = new CustomClass();
            //serialize it
            string result = new JsonFXDotNet().SerializeToJsonString(cc);  //JsonConvert.SerializeObject(cc);
            //encrypt it
            string encryptedMessage = pc.Encrypt(result);

            UUnitAssert.Equals("Zbr7pEF/GFGKj1rOstp0tWzA4nwJXEfj+ezLtAr8qqE=", encryptedMessage);
        }
Example #19
0
        public void TestPubNubEncryption2()
        {
            PubnubCrypto pc = new PubnubCrypto("enigma");
            //Deserialized
            string message = "Pubnub Messaging API 2";

            //serialize the message
            message = JsonConvert.SerializeObject(message);
            //encrypt
            string encryptedMessage = pc.Encrypt(message);

            Assert.True("f42pIQcWZ9zbTbH8cyLwB/tdvRxjFLOYcBNMVKeHS54=" == encryptedMessage);
        }
Example #20
0
        public void TestGermanCharsEncryptionMiniJson()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
            string       message      = "ÜÖ";

            message = Common.SerializeMiniJson(message);
            Console.WriteLine(message);
            string encrypted = pubnubCrypto.Encrypt(message);

            Console.WriteLine(encrypted);

            Assert.True(("stpgsG1DZZxb44J7mFNSzg==").Equals(encrypted));
        }
Example #21
0
        public void TestPubNubEncryption2MiniJson()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
            //Deserialized
            string message = "Pubnub Messaging API 2";

            //serialize the message
            message = Common.SerializeMiniJson(message);
            //encrypt
            string encrypted = pubnubCrypto.Encrypt(message);

            Assert.True(("f42pIQcWZ9zbTbH8cyLwB/tdvRxjFLOYcBNMVKeHS54=").Equals(encrypted));
        }
Example #22
0
        public void TestPubNubEncryption1MiniJson()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
            //non serialized string
            string message = "Pubnub Messaging API 1";

            //serialize
            message = Common.SerializeMiniJson(message);
            //encrypt
            string encrypted = pubnubCrypto.Encrypt(message);

            Assert.True(("f42pIQcWZ9zbTbH8cyLwByD/GsviOE0vcREIEVPARR0=").Equals(encrypted));
        }
Example #23
0
        public void TestPubNubEncryption1()
        {
            PubnubCrypto pc = new PubnubCrypto("enigma");
            //non serialized string
            string message = "Pubnub Messaging API 1";

            //serialize
            message = JsonConvert.SerializeObject(message);
            //Encrypt
            string encryptedMessage = pc.Encrypt(message);

            Assert.AreEqual("f42pIQcWZ9zbTbH8cyLwByD/GsviOE0vcREIEVPARR0=", encryptedMessage);
        }
Example #24
0
        public void TestArrayEncryption()
        {
            PubnubCrypto pc = new PubnubCrypto("enigma");

            //create an empty array object
            object[] emptyArray = { };
            //serialize
            string serializedArray = JsonConvert.SerializeObject(emptyArray);
            //Encrypt
            string encryptedMessage = pc.Encrypt(serializedArray);

            Assert.AreEqual("Ns4TB41JjT2NCXaGLWSPAQ==", encryptedMessage);
        }
Example #25
0
        private string JsonEncodePublishMsg(object originalMessage)
        {
            string message = jsonLibrary.SerializeToJsonString(originalMessage);

            if (config.CipherKey.Length > 0)
            {
                PubnubCrypto aes            = new PubnubCrypto(config.CipherKey, config, pubnubLog);
                string       encryptMessage = aes.Encrypt(message);
                message = jsonLibrary.SerializeToJsonString(encryptMessage);
            }

            return(message);
        }
Example #26
0
        public void TestYayEncryption()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
            //deserialized string
            string message = "yay!";

            //serialize the string
            message = Common.Serialize(message);
            Console.WriteLine(message);
            //Encrypt
            string encrypted = pubnubCrypto.Encrypt(message);

            Assert.True(("Wi24KS4pcTzvyuGOHubiXg==").Equals(encrypted));
        }
Example #27
0
        //will fail with minijson
        //[Test]
        public void TestMyObjectEncryptionMiniJson()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
            //create an object of the custom class
            CustomClass cc = new CustomClass();
            //serialize it
            string result = Common.SerializeMiniJson(cc);
            //encrypt it
            string encrypted = pubnubCrypto.Encrypt(result);

            UnityEngine.Debug.Log("encrypted:" + encrypted);
            UnityEngine.Debug.Log("result:" + result);
            Assert.True(("Zbr7pEF/GFGKj1rOstp0tWzA4nwJXEfj+ezLtAr8qqE=").Equals(encrypted));
        }
Example #28
0
        public void TestYayEncryption()
        {
            PubnubCrypto pc = new PubnubCrypto("enigma");
            //deserialized string
            string message = "yay!";

            //serialize the string
            message = JsonConvert.SerializeObject(message);
            //Console.WriteLine(message);
            //Encrypt
            string encryptedMessage = pc.Encrypt(message);

            Assert.AreEqual("Wi24KS4pcTzvyuGOHubiXg==", encryptedMessage);
        }
Example #29
0
        public void TestPubNubEncryption2()
        {
            Debug.Log("Running TestPubNubEncryption2()");
            PubnubCrypto pc = new PubnubCrypto("enigma");
            //Deserialized
            string message = "Pubnub Messaging API 2";

            //serialize the message
            message = JsonConvert.SerializeObject(message);
            //encrypt
            string encryptedMessage = pc.Encrypt(message);

            UUnitAssert.Equals("f42pIQcWZ9zbTbH8cyLwB/tdvRxjFLOYcBNMVKeHS54=", encryptedMessage);
        }
Example #30
0
        public void TestObjectEncryption()
        {
            Debug.Log("Running TestObjectEncryption()");
            PubnubCrypto pc = new PubnubCrypto("enigma");

            //create an object
            System.Object obj = new System.Object();
            //serialize
            string serializedObject = JsonConvert.SerializeObject(obj);
            //encrypt
            string encryptedMessage = pc.Encrypt(serializedObject);

            UUnitAssert.Equals("IDjZE9BHSjcX67RddfCYYg==", encryptedMessage);
        }