Exemplo n.º 1
0
        public void TestRandomIVGenCommon(string message)
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog, true);
            string       encrypted    = pubnubCrypto.Encrypt(message);
            string       decrypted    = pubnubCrypto.Decrypt(encrypted);

            UnityEngine.Debug.Log(decrypted);
            Assert.True(message.Equals(decrypted));
        }
Exemplo n.º 2
0
        public void TestYayDecryptionBasic()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            string       message      = "q/xJqqN6qbiZMXYmiQC1Fw==";
            //decrypt
            string decrypted = pubnubCrypto.Decrypt(message);

            Assert.True(("yay!").Equals(decrypted));
        }
Exemplo n.º 3
0
        public void TestStuffcanDecryption()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            //deserialized string
            string message = "zMqH/RTPlC8yrAZ2UhpEgLKUVzkMI2cikiaVg30AyUu7B6J0FLqCazRzDOmrsFsF";
            //decrypt
            string decrypted = pubnubCrypto.Decrypt(message);

            Assert.True(("{\"this stuff\":{\"can get\":\"complicated!\"}}").Equals(decrypted));
        }
Exemplo n.º 4
0
        public void TestHashDecryption()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            //deserialized string
            string message = "GsvkCYZoYylL5a7/DKhysDjNbwn+BtBtHj2CvzC4Y4g=";
            //decrypt
            string decrypted = pubnubCrypto.Decrypt(message);

            Assert.True(("{\"foo\":{\"bar\":\"foobar\"}}").Equals(decrypted));
        }
Exemplo n.º 5
0
        public void TestUnicodeCharsEncryptionMiniJson()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            string       message      = "漢語";

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

            Assert.That(("+BY5/miAA8aeuhVl4d13Kg==").Equals(encrypted));
        }
Exemplo n.º 6
0
        public void TestGermanCharsEncryptionMiniJson()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            string       message      = "ÜÖ";

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

            Assert.True(("stpgsG1DZZxb44J7mFNSzg==").Equals(encrypted));
        }
Exemplo n.º 7
0
        public void TestPAMSignature()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto crypto    = new PubnubCrypto("", PNLog);
            string       secretKey = "secret";
            string       message   = "Pubnub Messaging 1";

            string signature = crypto.PubnubAccessManagerSign(secretKey, message);

            Assert.True(("mIoxTVM2WAM5j-M2vlp9bVblDLoZQI5XIoYyQ48U0as=").Equals(signature));
        }
Exemplo n.º 8
0
        //[ExpectedException (typeof(ArgumentNullException))]
        public void TestNullDecryption()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            //deserialized string
            string message = null;
            //decrypt
            var ex = Assert.Throws <ArgumentNullException>(() => pubnubCrypto.Decrypt(message));

            Assert.That(ex.Message.Contains("Argument cannot be null."), ex.Message, null);
        }
Exemplo n.º 9
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));
        }
Exemplo n.º 10
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));
        }
Exemplo n.º 11
0
        public void TestPubNubDecryption2MiniJson()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            //Deserialized string
            string message = "f42pIQcWZ9zbTbH8cyLwB/tdvRxjFLOYcBNMVKeHS54=";
            //Decrypt
            string decrypted = pubnubCrypto.Decrypt(message);

            //Deserialize
            message = Common.DeserializeMiniJson <string> (decrypted);
            Assert.True(("Pubnub Messaging API 2").Equals(message));
        }
Exemplo n.º 12
0
        public void TestUnicodeCharsDecryptionMiniJson()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            string       message      = "+BY5/miAA8aeuhVl4d13Kg==";
            //decrypt
            string decrypted = pubnubCrypto.Decrypt(message);

            //deserialize
            message = Common.DeserializeMiniJson <string> (decrypted);

            Assert.True(("漢語").Equals(message));
        }
Exemplo n.º 13
0
        public void TestGermanCharsDecryptionMiniJson()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            string       message      = "stpgsG1DZZxb44J7mFNSzg==";
            //decrypt
            string decrypted = pubnubCrypto.Decrypt(message);

            //deserialize
            message = Common.DeserializeMiniJson <string> (decrypted);

            Assert.True(("ÜÖ").Equals(message));
        }
Exemplo n.º 14
0
        public void TestPubNubDecryption1MiniJson()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            //deserialized string
            string message = "f42pIQcWZ9zbTbH8cyLwByD/GsviOE0vcREIEVPARR0=";
            //decrypt
            string decrypted = pubnubCrypto.Decrypt(message);

            //deserialize
            message = Common.DeserializeMiniJson <string> (decrypted);
            Assert.True(("Pubnub Messaging API 1").Equals(message));
        }
Exemplo n.º 15
0
        public void TestPubNubEncryption2()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            //Deserialized
            string message = "Pubnub Messaging API 2";

            //serialize the message
            message = EditorCommon.Serialize(message);
            //encrypt
            string encrypted = pubnubCrypto.Encrypt(message);

            Assert.True(("f42pIQcWZ9zbTbH8cyLwB/tdvRxjFLOYcBNMVKeHS54=").Equals(encrypted));
        }
Exemplo n.º 16
0
        public void TestPubNubEncryption1MiniJson()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            //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));
        }
Exemplo n.º 17
0
        public void TestYayEncryption()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            //deserialized string
            string message = "yay!";

            //serialize the string
            message = EditorCommon.Serialize(message);
            //Encrypt
            string encrypted = pubnubCrypto.Encrypt(message);

            Assert.True(("Wi24KS4pcTzvyuGOHubiXg==").Equals(encrypted));
        }
Exemplo n.º 18
0
        //will fail with minijson
        //[Test]
        public void TestObjectDecryptionMiniJson()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            //Deserialized
            string message = "IDjZE9BHSjcX67RddfCYYg==";
            //Decrypt
            string decrypted = pubnubCrypto.Decrypt(message);
            //create an object
            Object obj = new Object();
            //Serialize the object
            string result = Common.SerializeMiniJson(obj);

            Assert.True((decrypted).Equals(result));
        }
Exemplo n.º 19
0
        //will fail with minijson
        //[Test]
        public void TestMyObjectEncryptionMiniJson()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            //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));
        }
Exemplo n.º 20
0
        public void TestArrayDecryptionUsingMiniJson()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            //Input the deserialized string
            string message = "Ns4TB41JjT2NCXaGLWSPAQ==";
            //decrypt
            string decrypted = pubnubCrypto.Decrypt(message);

            //create a serialized object
            object[] objArr = { };
            string   result = Common.SerializeMiniJson(objArr);

            //compare the serialized object and the return of the Decrypt method
            Assert.True((result).Equals(decrypted));
        }
Exemplo n.º 21
0
        public void TestYayDecryptionMiniJson()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            //Non deserialized string
            string message = "\"Wi24KS4pcTzvyuGOHubiXg==\"";

            //Deserialize
            message = Common.DeserializeMiniJson <string> (message);

            //decrypt
            string decrypted = pubnubCrypto.Decrypt(message);

            //deserialize again
            message = Common.DeserializeMiniJson <string> (decrypted);
            Assert.True(("yay!").Equals(message));
        }
Exemplo n.º 22
0
        public void TestMyObjectDecryption()
        {
            pn = EditorCommon.InitPN(pnConfig);
            PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma", PNLog);
            //Deserialized
            string message = "Zbr7pEF/GFGKj1rOstp0tWzA4nwJXEfj+ezLtAr8qqE=";
            //Decrypt
            string decrypted = pubnubCrypto.Decrypt(message);
            //create an object of the custom class
            CustomClass cc = new CustomClass();
            //Serialize it
            string result = EditorCommon.Serialize(cc);

            UnityEngine.Debug.Log("decrypted:" + decrypted);
            UnityEngine.Debug.Log("result:" + result);
            Assert.True((decrypted).Equals(result));
        }
Exemplo n.º 23
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));

            /* #if UNITY_2019_1_OR_NEWER
             * UnityEngine.Debug.Log ("UNITY_2019_1_OR_NEWER:" + ex.Message);*/

            Assert.That(ex.Message.Contains("Value cannot be null."), ex.Message, null);

            /* #else
            *  UnityEngine.Debug.Log ("!UNITY_2019_1_OR_NEWER:" + ex.Message);
            *  Assert.That(ex.Message.Contains("Argument cannot be null."),ex.Message, null);
            #endif*/
        }