예제 #1
0
        public static string Decrypt(string encrypt)
        {
            encrypt = encrypt.Replace("\n", "").Replace("\r", "").Replace(" ", "").Trim();
            Console.WriteLine("responseString:" + encrypt);
            //var josnObj = Newtonsoft.Json.Linq.JObject.Parse(encrypt);
            var    josnObj  = Newtonsoft.Json.Linq.JObject.Parse(encrypt);
            string text     = josnObj["text"].ToString();
            string password = josnObj["password"].ToString();

            password = MyEncrypt.DecryptRSA(password, MyKeys.CLIENT_PRIVATE_KEY, 2);
            password = password.Replace("\n", "").Replace("\r", "").Replace(" ", "").Trim();
            Console.WriteLine("password:"******"\n", "").Replace("\r", "").Replace(" ", "").Trim();
            text = MyEncrypt.DecryptDES(text, password);
            text = text.Replace("\n", "").Replace("\r", "").Replace(" ", "").Trim();
            var    jsonObject = Newtonsoft.Json.Linq.JObject.Parse(text);
            string character  = jsonObject["character"].ToString();
            string source     = jsonObject["source"].ToString().Replace("\n", "").Replace("\r", "").Replace(" ", "").Trim();

            character = MyEncrypt.DecryptRSA(character, MyKeys.SERVER_PUBLIC_KEY, 1);
            character = character.Replace("\n", "").Replace("\r", "").Replace(" ", "").Trim();
            String X = MyEncrypt.SHA1(UrlEncode(source, Encoding.UTF8));

            Console.WriteLine("source:" + source);
            Console.WriteLine("character:" + character);
            Console.WriteLine("X:" + X);
            if (X.Equals(character.ToUpper()))
            {
                return(source);
            }
            else
            {
                return("");
            }
        }
예제 #2
0
 public static void init()
 {
     MyKeys.GUID = GetGUID();
     string[] key = MyEncrypt.GenerateKey();
     MyKeys.CLIENT_PUBLIC_KEY  = key[0];
     MyKeys.CLIENT_PRIVATE_KEY = key[1];
     MyKeys.SERVER_PUBLIC_KEY  = getServerKey();
 }
예제 #3
0
        public static string Encrypt(string source)
        {
            string result = "";

            source = source.Replace("\n", "").Replace("\r", "").Replace(" ", "").Trim();
            string X         = MyEncrypt.SHA1(UrlEncode(source, Encoding.UTF8));
            string character = MyEncrypt.EncryptRSA(X, MyKeys.CLIENT_PRIVATE_KEY, 2);
            string C         = "{\"source\":\"" + source
                               + "\",\"character\":\"" + character + "\"}";
            string Q = generateString(8);
            string D = MyEncrypt.EncryptDES(C, Q);
            string P = MyEncrypt.EncryptRSA(Q, MyKeys.SERVER_PUBLIC_KEY, 1);

            result = "&text=" + UrlEncode(D, Encoding.UTF8)
                     + "&password=" + UrlEncode(P, Encoding.UTF8);
            return(result);
        }