Example #1
0
		public static void ResponseScript(KeyValueList r, bool compress)
		{
			string e = "{}";
			try
			{
				e = Helper.Encode(r, compress);
			}
			catch (Exception ex)
			{
				r.SetValue("ErrorCode", 1);
				r.SetValue("ErrorMessage", ex.Message);
			}
			// Encode to base64 string.
			var sender = "{ Compressed: " + compress.ToString().ToLower() + " }";
			var s = "System.Web.Mobile.DataLoaded(" + sender + ", '" + e + "');";
			ResponseScript(s);
		}
Example #2
0
        public void PostData(DataType key, string value)
        {
            var r = new KeyValueList();

            r.SetValue("ErrorCode", 0);
            r.SetValue("ErrorMessage", "");
            r.SetValue("DataType", Convert.ToInt32(key));
            switch (key)
            {
            case DataType.GetRsaKey:
                // Tell IIS to use Machine Key store or creation of RSA service provider will fail.
                var cspParams = new CspParameters();
                cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
                // Create a new instance of RSACryptoServiceProvider.
                var rsa = new System.Security.Cryptography.RSACryptoServiceProvider(1024, cspParams);
                // Import parameters from xml.
                rsa.FromXmlString(xmlParams);
                // Export RSA key to RSAParameters and include:
                //    false - Only public key required for encryption.
                //    true  - Private key required for decryption.
                var rsaPublicKey = rsa.ToXmlString(false);
                r.SetValue("RsaPublicKey", rsaPublicKey);
                break;

            case DataType.SendProfile:
                r.Load(value, true);
                var profile = r.GetValue <UserProfile>("UserProfile");
                var card    = r.GetValue <Card>("Card");
                // Get password from RSA encrypted data.
                var password = Helper.RsaDecrypt(card.EncryptedPass, xmlParams);
                var s        = Helper.AesDecrypt(password, card.EncryptedData);
                card = Helper.DeSerialize <Card>(s);
                r.SetValue("Message", string.Format("Server decrypted '{0}' card with number: {1}", card.Name, card.Number));
                break;

            default:
                break;
            }
            Helper.ResponseScript(r, true);
        }