Ejemplo n.º 1
0
        public void TestNullDecryption()
        {
            bool isExpectedException = false;
            string decryptedMessage = "";
            ThreadPool.QueueUserWorkItem((s) =>
                {
                    PubnubCrypto pc = new PubnubCrypto("enigma");
                    //deserialized string
                    string message = null;
                    try
                    {
                        //Decrypt
                        decryptedMessage = pc.Decrypt(message);
                    }
                    catch (ArgumentNullException)
                    {
                        isExpectedException = true;
                    }

                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            //Assert.AreEqual("", dec);
                            Assert.IsTrue(isExpectedException);
                            TestComplete();
                        });
                });
        }
Ejemplo n.º 2
0
        public void TestYayDecryptionBasic ()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto ("enigma");
            string message = "q/xJqqN6qbiZMXYmiQC1Fw==";
            //decrypt
            string decrypted = pubnubCrypto.Decrypt (message);

            Assert.True (("yay!").Equals (decrypted));
        }
Ejemplo n.º 3
0
 public void TestYayEncryptionBasic ()
 {
     PubnubCrypto pubnubCrypto = new PubnubCrypto ("enigma");
     //deserialized string
     string message = "yay!";
     //Encrypt
     string encrypted = pubnubCrypto.Encrypt (message);
     Assert.True (("q/xJqqN6qbiZMXYmiQC1Fw==").Equals (encrypted));
 }
Ejemplo n.º 4
0
 public void TestNullEncryption()
 {
     PubnubCrypto pc = new PubnubCrypto("enigma");
     //serialized string
     string message = null;
     
     //encrypt
     string encryptedMessage = pc.Encrypt(message);
 }
Ejemplo n.º 5
0
 public void TestYayDecryptionBasic()
 {
     PubnubCrypto pc = new PubnubCrypto("enigma");
     string message = "q/xJqqN6qbiZMXYmiQC1Fw==";
     //decrypt
     string decryptedMessage = pc.Decrypt(message);
     //deserialize again
     Assert.AreEqual("yay!", decryptedMessage);
 }
Ejemplo n.º 6
0
 public void TestGermanCharsDecryption()
 {
     PubnubCrypto pc = new PubnubCrypto("enigma");
     string message = "stpgsG1DZZxb44J7mFNSzg==";
     //Decrypt
     string decryptedMessage = pc.Decrypt(message);
     //deserialize
     message = (decryptedMessage != "**DECRYPT ERROR**") ? JsonConvert.DeserializeObject<string>(decryptedMessage) : "";
     Assert.AreEqual("ÜÖ", message);
 }
Ejemplo n.º 7
0
        public void TestNullDecryption()
        {
            PubnubCrypto pc = new PubnubCrypto("enigma");
            //deserialized string
            string message = null;
            //decrypt
            string decryptedMessage = pc.Decrypt(message);

            Assert.AreEqual("", decryptedMessage);
        }
Ejemplo n.º 8
0
        public void TestGermanCharsEncryption()
        {
            PubnubCrypto pc = new PubnubCrypto("enigma");
            string message = "ÜÖ";

            message = JsonConvert.SerializeObject(message);

            string encryptedMessage = pc.Encrypt(message);

            Assert.AreEqual("stpgsG1DZZxb44J7mFNSzg==", encryptedMessage);
        }
Ejemplo n.º 9
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);
 }
Ejemplo n.º 10
0
 public void TestYayEncryption ()
 {
     PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
     //deserialized string
     string message= "yay!";
     //serialize the string
     message= JsonConvert.SerializeObject(message);
     Console.WriteLine(message);
     //Encrypt
     string encrypted= pubnubCrypto.Encrypt(message);
     Assert.AreEqual("Wi24KS4pcTzvyuGOHubiXg==", encrypted);
 }
Ejemplo n.º 11
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));
    }
Ejemplo n.º 12
0
 public void TestYayDecryption ()
 {
     PubnubCrypto pubnubCrypto = new PubnubCrypto("enigma");
     //Non deserialized string
     string message= "\"Wi24KS4pcTzvyuGOHubiXg==\"";
     //Deserialize 
     message= JsonConvert.DeserializeObject<string>(message);
     //decrypt
     string decrypted= pubnubCrypto.Decrypt(message);
     //deserialize again
     message= JsonConvert.DeserializeObject<string>(decrypted);
     Assert.AreEqual("yay!", message);
 }
Ejemplo n.º 13
0
 public void TestArrayDecryption()
 {
     PubnubCrypto pc = new PubnubCrypto("enigma");
     //Input the deserialized string
     string message = "Ns4TB41JjT2NCXaGLWSPAQ==";
     //Decrypt
     string decryptedMessage = pc.Decrypt(message);
     //create a serialized object
     object[] emptyArrayObject = { };
     string result = JsonConvert.SerializeObject(emptyArrayObject);
     //compare the serialized object and the return of the Decrypt method
     Assert.AreEqual(result, decryptedMessage);
 }
Ejemplo n.º 14
0
        public void TestYayDecryptionMiniJson ()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto ("enigma");
            //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));
        }
Ejemplo n.º 15
0
 public void TestArrayEncryption()
 {
     ThreadPool.QueueUserWorkItem((s) =>
         {
             PubnubCrypto pc = new PubnubCrypto("enigma");
             //create an empty array object
             object[] emptyArray = { };
             //serialize
             string serializedArray = JsonConvert.SerializeObject(emptyArray);
             //Encrypt
             string encryptedMessage = pc.Encrypt(serializedArray);
             Deployment.Current.Dispatcher.BeginInvoke(() =>
                 {
                     Assert.AreEqual("Ns4TB41JjT2NCXaGLWSPAQ==", encryptedMessage);
                     TestComplete();
                 });
         });
 }
Ejemplo n.º 16
0
        public void TestNullDecryption()
        {
            bool isExpectedException = false;
            string decryptedMessage = "";
            PubnubCrypto pc = new PubnubCrypto("enigma");
            //deserialized string
            string message = null;
            try
            {
                //Decrypt
                decryptedMessage = pc.Decrypt(message);
            }
            catch (ArgumentNullException)
            {
                isExpectedException = true;
            }

            Assert.IsTrue(isExpectedException);
        }
Ejemplo n.º 17
0
        internal static object DecodeMessage(PubnubCrypto aes, object element, string[] channels,
                                             Action <PubnubClientError> errorCallback, IJsonPluggableLibrary jsonPluggableLibrary,
                                             PubnubErrorFilter.Level errorLevel)
        {
            string decryptMessage = "";

            try {
                decryptMessage = aes.Decrypt(element.ToString());
            }
            catch (Exception ex) {
                decryptMessage = "**DECRYPT ERROR**";
                string multiChannel = string.Join(",", channels);
                PubnubCallbacks.CallErrorCallback <object> (ex, null, multiChannel, PubnubErrorCode.None,
                                                            PubnubErrorSeverity.Critical, errorCallback, errorLevel);
            }
            object decodeMessage = (decryptMessage == "**DECRYPT ERROR**") ? decryptMessage : jsonPluggableLibrary.DeserializeToObject(decryptMessage);

            return(decodeMessage);
        }
Ejemplo n.º 18
0
 public void TestArrayDecryption()
 {
     ThreadPool.QueueUserWorkItem((s) =>
         {
             PubnubCrypto pc = new PubnubCrypto("enigma");
             //Input the deserialized string
             string message = "Ns4TB41JjT2NCXaGLWSPAQ==";
             //Decrypt
             string decryptedMessage = pc.Decrypt(message);
             //create a serialized object
             object[] emptyArrayObject = { };
             string result = JsonConvert.SerializeObject(emptyArrayObject);
             //compare the serialized object and the return of the Decrypt method
             Deployment.Current.Dispatcher.BeginInvoke(() =>
                 {
                     Assert.AreEqual(result, decryptedMessage);
                     TestComplete();
                 });
         });
 }
Ejemplo n.º 19
0
        public void TestNullEncryption()
        {
			Debug.Log("Running TestNullEncryption()");
			bool isExpectedException = false;
			
            PubnubCrypto pc = new PubnubCrypto("enigma");
            //serialized string
            string message = null;

            try
            {
                //Encrypt
                pc.Encrypt(message);
            }
            catch (ArgumentNullException)
            {
                isExpectedException = true;
            }

            UUnitAssert.True(isExpectedException);

        }
Ejemplo n.º 20
0
        internal static List <object> AddMessageToList(string cipherKey, IJsonPluggableLibrary jsonPluggableLibrary,
                                                       object[] messages, int messageIndex, string currentChannel, object[] messageList)
        {
            List <object> itemMessage = new List <object>();

            if (currentChannel.Contains(Utility.PresenceChannelSuffix))
            {
                itemMessage.Add(messageList[messageIndex]);
            }
            else
            {
                //decrypt the subscriber message if cipherkey is available
                if (cipherKey.Length > 0)
                {
                    object decodeMessage;
                    try
                    {
                        PubnubCrypto aes            = new PubnubCrypto(cipherKey);
                        string       decryptMessage = aes.Decrypt(messageList[messageIndex].ToString());
                        decodeMessage = (decryptMessage == "**DECRYPT ERROR**") ? decryptMessage : jsonPluggableLibrary.DeserializeToObject(decryptMessage);
                    }
                    catch (Exception decryptEx)
                    {
                        decodeMessage = messageList[messageIndex].ToString();
                        #if (ENABLE_PUBNUB_LOGGING)
                        LoggingMethod.WriteToLog(string.Format("DateTime {0}, decodeMessage Exception: {1}", DateTime.Now.ToString(), decryptEx.ToString()), LoggingMethod.LevelError);
                        #endif
                    }
                    itemMessage.Add(decodeMessage);
                }
                else
                {
                    itemMessage.Add(messageList[messageIndex]);
                }
            }
            itemMessage.Add(messages[1].ToString());
            itemMessage.Add(currentChannel.Replace(Utility.PresenceChannelSuffix, ""));
            return(itemMessage);
        }
Ejemplo n.º 21
0
        internal static Uri BuildChannelGroupGrantAccessRequest(string channelGroup, bool read, bool write, bool manage, int ttl, string uuid,
                                                                bool ssl, string origin, string authenticationKey,
                                                                string publishKey, string subscribeKey, string cipherKey, string secretKey)
        {
            string        signature          = "0";
            long          timeStamp          = Utility.TranslateDateTimeToSeconds(DateTime.UtcNow);
            string        queryString        = "";
            StringBuilder queryStringBuilder = new StringBuilder();

            if (!string.IsNullOrEmpty(authenticationKey))
            {
                queryStringBuilder.AppendFormat("auth={0}", Utility.EncodeUricomponent(authenticationKey, ResponseType.ChannelGroupGrantAccess, false, false));
            }

            if (!string.IsNullOrEmpty(channelGroup))
            {
                queryStringBuilder.AppendFormat("{0}channel-group={1}", (queryStringBuilder.Length > 0) ? "&" : "",
                                                Utility.EncodeUricomponent(channelGroup, ResponseType.ChannelGroupGrantAccess, false, false));
            }

            queryStringBuilder.AppendFormat("{0}", (queryStringBuilder.Length > 0) ? "&" : "");
            queryStringBuilder.AppendFormat("m={0}", Convert.ToInt32(manage));
            queryStringBuilder.AppendFormat("&pnsdk={0}", Utility.EncodeUricomponent(PubnubUnity.Version, ResponseType.ChannelGroupGrantAccess, false, true));
            queryStringBuilder.AppendFormat("&r={0}", Convert.ToInt32(read));
            queryStringBuilder.AppendFormat("&timestamp={0}", timeStamp.ToString());
            if (ttl > -1)
            {
                queryStringBuilder.AppendFormat("&ttl={0}", ttl.ToString());
            }
            queryStringBuilder.AppendFormat("&uuid={0}", Utility.EncodeUricomponent(uuid, ResponseType.ChannelGroupGrantAccess, false, false));
            //queryStringBuilder.AppendFormat("&w={0}", Convert.ToInt32(write)); Not supported at this time.

            if (secretKey.Length > 0)
            {
                StringBuilder string_to_sign = new StringBuilder();
                string_to_sign.Append(subscribeKey)
                .Append("\n")
                .Append(publishKey)
                .Append("\n")
                .Append("grant")
                .Append("\n")
                .Append(queryStringBuilder.ToString());

                PubnubCrypto pubnubCrypto = new PubnubCrypto(cipherKey);
                signature   = pubnubCrypto.PubnubAccessManagerSign(secretKey, string_to_sign.ToString());
                queryString = string.Format("signature={0}&{1}", signature, queryStringBuilder.ToString());
            }

            string parameters = "";

            parameters += "?" + queryString;

            List <string> url = new List <string>();

            url.Add("v1");
            url.Add("auth");
            url.Add("grant");
            url.Add("sub-key");
            url.Add(subscribeKey);

            return(BuildRestApiRequest <Uri>(url, ResponseType.ChannelGroupGrantAccess,
                                             uuid, ssl, origin, 0, authenticationKey, parameters));
        }
Ejemplo n.º 22
0
        public void TestPAMSignature ()
        {
            PubnubCrypto crypto = new PubnubCrypto ("");
            string secretKey = "secret";
            string message = "Pubnub Messaging 1";

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

            Assert.True (("mIoxTVM2WAM5j-M2vlp9bVblDLoZQI5XIoYyQ48U0as=").Equals (signature));
        }
Ejemplo n.º 23
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));
        }
Ejemplo n.º 24
0
        public void TestGermanCharsDecryptionMiniJson ()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto ("enigma");
            string message = "stpgsG1DZZxb44J7mFNSzg==";
            //decrypt
            string decrypted = pubnubCrypto.Decrypt (message);
            //deserialize
            message = Common.DeserializeMiniJson<string> (decrypted);

            Assert.True (("ÜÖ").Equals (message));
        }
Ejemplo n.º 25
0
        public void TestUnicodeCharsDecryptionMiniJson ()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto ("enigma");
            string message = "+BY5/miAA8aeuhVl4d13Kg==";
            //decrypt
            string decrypted = pubnubCrypto.Decrypt (message);
            //deserialize
            message = Common.DeserializeMiniJson<string> (decrypted);

            Assert.True (("漢語").Equals (message));
        }
Ejemplo n.º 26
0
 public void TestUnicodeCharsEncryptionMiniJson ()
 {
     PubnubCrypto pubnubCrypto = new PubnubCrypto ("enigma");
     string message = "漢語";
     message = Common.SerializeMiniJson (message);
     Console.WriteLine (message);
     string encrypted = pubnubCrypto.Encrypt (message);
     Console.WriteLine (encrypted);
     Assert.That (("+BY5/miAA8aeuhVl4d13Kg==").Equals (encrypted));
 }
Ejemplo n.º 27
0
        public void TestNullDecryption ()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto ("enigma");
            //deserialized string
            string message = null;
            //decrypt
            string decrypted = pubnubCrypto.Decrypt (message);

            Assert.True (("").Equals (decrypted));
        }
Ejemplo n.º 28
0
        public void TestHashDecryption ()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto ("enigma");
            //deserialized string
            string message = "GsvkCYZoYylL5a7/DKhysDjNbwn+BtBtHj2CvzC4Y4g=";
            //decrypt
            string decrypted = pubnubCrypto.Decrypt (message);

            Assert.True (("{\"foo\":{\"bar\":\"foobar\"}}").Equals (decrypted));
        }
Ejemplo n.º 29
0
        public void TestStuffcanDecryption ()
        {
            PubnubCrypto pubnubCrypto = new PubnubCrypto ("enigma");
            //deserialized string
            string message = "zMqH/RTPlC8yrAZ2UhpEgLKUVzkMI2cikiaVg30AyUu7B6J0FLqCazRzDOmrsFsF";
            //decrypt
            string decrypted = pubnubCrypto.Decrypt (message);

            Assert.True (("{\"this stuff\":{\"can get\":\"complicated!\"}}").Equals (decrypted));
        }
Ejemplo n.º 30
0
 public void TestPubNubDecryption1MiniJson ()
 {
     PubnubCrypto pubnubCrypto = new PubnubCrypto ("enigma");
     //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));
 }
Ejemplo n.º 31
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));
        }
Ejemplo n.º 32
0
 public void TestPubNubDecryption2MiniJson ()
 {
     PubnubCrypto pubnubCrypto = new PubnubCrypto ("enigma");
     //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));
 }
Ejemplo n.º 33
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));
        }