コード例 #1
0
 public KeyMaterial(string cryptoAlg, string curve, KeyStructure dhPublicKey, string nonce)
 {
     CryptoAlg   = cryptoAlg;
     Curve       = curve;
     DhPublicKey = dhPublicKey;
     Nonce       = nonce;
 }
コード例 #2
0
        public bool LoadKey(KeyStructure keyStructure, byte keyNumber, byte[] key)
        {
            var loadKeyCmd = new CommandApdu(IsoCase.Case3Short, SCardProtocol.Any)
            {
                CLA         = CUSTOM_CLA,
                Instruction = InstructionCode.ExternalAuthenticate,
                P1          = (byte)keyStructure,
                P2          = keyNumber,
                Data        = key
            };

            //Debug.WriteLine($"Load Authentication Keys: {BitConverter.ToString(loadKeyCmd.ToArray())}");
            var response = _isoreader.Transmit(loadKeyCmd);

            //Debug.WriteLine($"SW1 SW2 = {response.SW1:X2} {response.SW2:X2}");

            return(IsSuccess(response));
        }
コード例 #3
0
        public bool LoadKey(KeyStructure keyStructure, byte keyNumber, byte[] key)
        {
            var loadKeyCmd = new CommandApdu(IsoCase.Case3Short, SCardProtocol.Any)
            {
                CLA         = _customCla,
                Instruction = InstructionCode.ExternalAuthenticate,
                P1          = (byte)keyStructure,
                P2          = keyNumber,
                Data        = key
            };

            Debug.WriteLine("Load Authentication Keys: {0}", BitConverter.ToString(loadKeyCmd.ToArray()));
            var response = _isoReader.Transmit(loadKeyCmd);

            Debug.WriteLine("SW1 SW2 = {0:X2} {1:X2}", response.SW1, response.SW2);

            return(IsSuccess(response));
        }
コード例 #4
0
ファイル: MifareCard.cs プロジェクト: thiti-y/pcsc-sharp
        public bool LoadKey(KeyStructure keyStructure, int keyNumber, byte[] key) {
            unchecked {

                var loadKeyCmd = new CommandApdu(IsoCase.Case3Short, SCardProtocol.Any) {
                    CLA = 0xFF,
                    Instruction = InstructionCode.ExternalAuthenticate,
                    P1 = (byte) keyStructure,
                    P2 = (byte) keyNumber,
                    Data = key
                };

                Debug.WriteLine(string.Format("Load Authentication Keys: {0}", BitConverter.ToString(loadKeyCmd.ToArray())));
                var response = _isoReader.Transmit(loadKeyCmd);
                Debug.WriteLine(string.Format("SW1 SW2 = {0:X2} {1:X2}", response.SW1, response.SW2));

                return Success(response);
            }
        }
コード例 #5
0
ファイル: keyboard.cs プロジェクト: Brave-cee/workplace
        private int Proc(int Code, int wParam, ref KeyStructure lParam)
        {
            if (Code == 0)
            {
                switch (wParam)
                {
                case 0x100:
                case 0x104:
                {
                    Down?.Invoke(Feed((Keys)lParam.Code));
                    break;
                }

                case 0x101:
                case 0x105:
                {
                    Up?.Invoke(Feed((Keys)lParam.Code));
                    break;
                }
                }
            }

            return(CallNextHookEx(Key, Code, wParam, ref lParam));
        }
コード例 #6
0
ファイル: AUDBTool.cs プロジェクト: aaay-aaay/AUDBTool
        // Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00001050
        private static void Main()
        {
            Console.SetIn(new StreamReader(Console.OpenStandardInput(8192), Console.InputEncoding, false, 8192));
            WebClient webClient = new WebClient();

            AUDBTool.CheckUpdate(webClient);
            bool flag = false;
            RSACryptoServiceProvider rsacryptoServiceProvider = new RSACryptoServiceProvider();
            RSAParameters            rsaparameters            = default(RSAParameters);
            bool flag2 = false;

            if (File.Exists("AUDB_RSA_KEY.txt"))
            {
                if (AUDBTool.Prompt("Existing key found, use it?", new string[]
                {
                    "y",
                    "n"
                }) == "y")
                {
                    rsaparameters = AUDBTool.ReadKey(rsaparameters, "AUDB_RSA_KEY.txt");
                    flag2         = true;
                    flag          = true;
                }
            }
            if (!flag2 && File.Exists("RSA_KEY.txt"))
            {
                if (AUDBTool.Prompt("Existing key from ToolMain found, use it?", new string[]
                {
                    "y",
                    "n"
                }) == "y")
                {
                    rsaparameters = AUDBTool.ReadKey(rsaparameters, "RSA_KEY.txt");
                    flag2         = true;
                    flag          = true;
                }
            }
            if (!flag2)
            {
                if (AUDBTool.Prompt("No key was found, or you chose not to read them. Generate a key?", new string[]
                {
                    "y",
                    "n"
                }) == "y")
                {
                    using (RSACryptoServiceProvider rsacryptoServiceProvider2 = new RSACryptoServiceProvider(4096))
                    {
                        rsaparameters = rsacryptoServiceProvider2.ExportParameters(true);
                    }
                    flag2 = true;
                }
            }
            string[] options;
            if (flag2)
            {
                rsacryptoServiceProvider.ImportParameters(rsaparameters);
                options = new string[]
                {
                    "save",
                    "close",
                    "raw",
                    "newmod",
                    "uploadmod",
                    "uploadthumb",
                    "sign",
                    "versions",
                    "hash"
                };
            }
            else
            {
                options = new string[]
                {
                    "close",
                    "raw",
                    "versions",
                    "hash"
                };
                flag = true;
            }
            string text = null;
            int    num  = -1;
            int    num2 = -1;

            if (flag2)
            {
                num2 = AUDBTool.GetKeyID(rsaparameters, webClient);
            }
            for (;;)
            {
                try
                {
                    bool   flag3 = text != null;
                    string text2 = text ?? AUDBTool.Prompt("What do you want to do?", options);
                    switch (text2)
                    {
                    case "save":
                    {
                        string text3 = null;
                        if (AUDBTool.Prompt("Do you want to save it in the default place? This will let AUDBTool automatically detect it next time, but will overwrite any existing text file called AUDB_RSA_KEY (.txt)", new string[]
                            {
                                "y",
                                "n"
                            }) == "y")
                        {
                            text3 = "AUDB_RSA_KEY.txt";
                        }
                        while (text3 == null)
                        {
                            Console.Write("Where do you want to save it then? ");
                            text3 = Console.ReadLine();
                            if (AUDBTool.Prompt("Are you sure you want to save it in " + text3 + "?", new string[]
                                {
                                    "y",
                                    "n"
                                }) == "n")
                            {
                                text3 = null;
                            }
                        }
                        AUDBTool.SaveKey(rsaparameters, text3);
                        flag = true;
                        break;
                    }

                    case "close":
                    {
                        string text4 = "Are you sure you want to close the AUDBTool?";
                        if (!flag)
                        {
                            text4 += " You have an unsaved key!";
                        }
                        if (AUDBTool.Prompt(text4, new string[]
                            {
                                "y",
                                "n"
                            }) == "y")
                        {
                            return;
                        }
                        break;
                    }

                    case "raw":
                        if (!(AUDBTool.Prompt("You have chosen to interact directly with the API. Are you sure?", new string[]
                        {
                            "y",
                            "n"
                        }) == "n"))
                        {
                            string stringFromURL = AUDBTool.GetStringFromURL(webClient, "http://beestuff.pythonanywhere.com/api");
                            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
                            ApiEndpointResponse  apiEndpointResponse  = javaScriptSerializer.Deserialize <ApiEndpointResponse>(stringFromURL);
                            foreach (ApiEndpointResponse.EndpointData endpointData in apiEndpointResponse.endpoints)
                            {
                                Console.WriteLine("Endpoint at " + endpointData.type + " " + endpointData.path);
                            }
                            bool flag4 = false;
                            while (!flag4)
                            {
                                Console.Write("Enter an endpoint, or anything else to go back to the main AUDBTool. ");
                                string text5 = Console.ReadLine();
                                ApiEndpointResponse.EndpointData endpointData2 = null;
                                foreach (ApiEndpointResponse.EndpointData endpointData in apiEndpointResponse.endpoints)
                                {
                                    if (endpointData.type + " " + endpointData.path == text5)
                                    {
                                        endpointData2 = endpointData;
                                    }
                                }
                                if (endpointData2 == null)
                                {
                                    if (AUDBTool.Prompt("Do you want to quit the raw interaction?", new string[]
                                    {
                                        "y",
                                        "n"
                                    }) == "y")
                                    {
                                        flag4 = true;
                                        break;
                                    }
                                }
                                else if (endpointData2.flags.Contains("key") && !flag2)
                                {
                                    Console.WriteLine("This endpoint requires a key, but you do not have one.");
                                }
                                else
                                {
                                    string a = text5.Split(new char[]
                                    {
                                        ' '
                                    })[0];
                                    string str = AUDBTool.DoFormat(text5.Split(new char[]
                                    {
                                        ' '
                                    })[1]);
                                    if (a != "GET")
                                    {
                                        Console.WriteLine("Currently only GET requests are supported");
                                    }
                                    else
                                    {
                                        if (endpointData2.flags.Contains("auth"))
                                        {
                                            AUDBTool.DoAuthstring(webClient, rsacryptoServiceProvider, rsaparameters, javaScriptSerializer);
                                        }
                                        if (endpointData2.flags.Contains("key"))
                                        {
                                            webClient.Headers.Set("Authorization-E", Convert.ToBase64String(rsaparameters.Exponent));
                                            webClient.Headers.Set("Authorization-N", Convert.ToBase64String(rsaparameters.Modulus));
                                        }
                                        if (a == "GET")
                                        {
                                            string stringFromURL2 = AUDBTool.GetStringFromURL(webClient, "http://beestuff.pythonanywhere.com" + str);
                                            Console.WriteLine("The response: " + stringFromURL2);
                                        }
                                    }
                                }
                            }
                        }
                        break;

                    case "newmod":
                    {
                        string stringFromURL = AUDBTool.GetStringFromURL(webClient, "http://beestuff.pythonanywhere.com/api");
                        JavaScriptSerializer             javaScriptSerializer = new JavaScriptSerializer();
                        ApiEndpointResponse              apiEndpointResponse  = javaScriptSerializer.Deserialize <ApiEndpointResponse>(stringFromURL);
                        ApiEndpointResponse.EndpointData endpointData3        = null;
                        foreach (ApiEndpointResponse.EndpointData endpointData in apiEndpointResponse.endpoints)
                        {
                            if (endpointData.path == "/audb/api/mods/new")
                            {
                                endpointData3 = endpointData;
                            }
                        }
                        if (endpointData3 == null)
                        {
                            Console.WriteLine("Mod creation endpoint couldn't be found, sorry!");
                            Console.WriteLine("This is probably an internal problem with the API, or you have an outdated version of AUDBTool.");
                            if (AUDBTool.Prompt("Do you want to quit the tool now?", new string[]
                                {
                                    "y",
                                    "n"
                                }) == "y")
                            {
                                return;
                            }
                        }
                        else
                        {
                            AUDBTool.DoAuthstring(webClient, rsacryptoServiceProvider, rsaparameters, javaScriptSerializer);
                            Dictionary <string, object> dictionary = new Dictionary <string, object>();
                            foreach (string text6 in ((Dictionary <string, object>)endpointData3.request).Keys)
                            {
                                if (((Dictionary <string, object>)endpointData3.request)[text6] is string && (string)((Dictionary <string, object>)endpointData3.request)[text6] == "string")
                                {
                                    Console.Write("Please enter " + text6 + ": ");
                                    dictionary[text6] = Console.ReadLine();
                                }
                                else if (((Dictionary <string, object>)endpointData3.request)[text6] is string && (string)((Dictionary <string, object>)endpointData3.request)[text6] == "bool")
                                {
                                    dictionary[text6] = (AUDBTool.Prompt(text6 + "?", new string[]
                                        {
                                            "y",
                                            "n"
                                        }) == "y");
                                }
                                else
                                {
                                    dictionary[text6] = null;
                                }
                            }
                            string text7 = AUDBTool.PostStringToURL(webClient, "http://beestuff.pythonanywhere.com/audb/api/mods/new", javaScriptSerializer.Serialize(dictionary));
                            Console.WriteLine("// Code for AutoUpdate support");
                            Console.WriteLine("// Should be put in the main PartialityMod class.");
                            Console.WriteLine("// Comments are optional.");
                            Console.WriteLine();
                            Console.WriteLine("// Update URL - don't touch!");
                            Console.WriteLine("// You can go to this in a browser (it's safe), but you might not understand the result.");
                            Console.WriteLine("// This URL is specific to this mod, and identifies it on AUDB.");
                            Console.WriteLine("public string updateURL = \"{0}\";", text7);
                            Console.WriteLine("// Version - increase this by 1 when you upload a new version of the mod.");
                            Console.WriteLine("// The first upload should be with version 0, the next version 1, the next version 2, etc.");
                            Console.WriteLine("// If you ever lose track of the version you're meant to be using, ask Pastebin.");
                            Console.WriteLine("public int version = 0;");
                            Console.WriteLine("// Public key in base64 - don't touch!");
                            Console.WriteLine("public string keyE = \"{0}\";", Convert.ToBase64String(rsaparameters.Exponent));
                            Console.WriteLine("public string keyN = \"{0}\";", Convert.ToBase64String(rsaparameters.Modulus));
                            Console.WriteLine("// ------------------------------------------------");
                            Console.WriteLine("If you include the code above and upload the mod, it will immediately be able to support AutoUpdate.");
                            if (AUDBTool.Prompt("Would you like to upload the mod?", new string[]
                                {
                                    "y",
                                    "n"
                                }) == "y")
                            {
                                text = "uploadmod";
                                string[] array = text7.Split(new char[]
                                    {
                                        '/'
                                    });
                                num = int.Parse(array[array.Length - 1]);
                            }
                        }
                        break;
                    }

                    case "uploadmod":
                    {
                        JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
                        string       stringFromURL3 = AUDBTool.GetStringFromURL(webClient, "http://beestuff.pythonanywhere.com/keydb/api/keys/" + num2.ToString());
                        KeyStructure keyStructure   = javaScriptSerializer.Deserialize <KeyStructure>(stringFromURL3);
                        for (int i = 0; i < keyStructure.audb.mods.Count; i++)
                        {
                            Console.WriteLine("Mod ID {0}: {1}", i, keyStructure.audb.mods[i].metadata.name);
                        }
                        if (num == -1)
                        {
                            num = AUDBTool.PromptInt("Please enter the mod ID you want to upload.");
                        }
                        Console.Write("Please enter the filename of the mod to upload: ");
                        string text8   = Console.ReadLine();
                        byte[] buffer  = File.ReadAllBytes(text8);
                        byte[] inArray = rsacryptoServiceProvider.SignData(buffer, "SHA512");
                        string value   = Convert.ToBase64String(inArray);
                        AUDBTool.DoAuthstring(webClient, rsacryptoServiceProvider, rsaparameters, javaScriptSerializer);
                        webClient.Headers.Set("modsig", value);
                        AUDBTool.PostFileToURL(webClient, "http://beestuff.pythonanywhere.com/audb/api/mods/" + num.ToString() + "/upload", text8);
                        num = -1;
                        break;
                    }

                    case "uploadthumb":
                    {
                        JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
                        string       stringFromURL4 = AUDBTool.GetStringFromURL(webClient, "http://beestuff.pythonanywhere.com/keydb/api/keys/" + num2.ToString());
                        KeyStructure keyStructure2  = javaScriptSerializer.Deserialize <KeyStructure>(stringFromURL4);
                        for (int i = 0; i < keyStructure2.audb.mods.Count; i++)
                        {
                            Console.WriteLine("Mod ID {0}: {1}", i, keyStructure2.audb.mods[i].metadata.name);
                        }
                        if (num == -1)
                        {
                            num = AUDBTool.PromptInt("Please enter the mod ID you want to upload the thumbnail (image) of.");
                        }
                        Console.Write("Please enter the filename of the image you want to upload: ");
                        string text9  = Console.ReadLine();
                        byte[] array2 = File.ReadAllBytes(text9);
                        AUDBTool.DoAuthstring(webClient, rsacryptoServiceProvider, rsaparameters, javaScriptSerializer);
                        AUDBTool.PostFileToURL(webClient, "http://beestuff.pythonanywhere.com/audb/api/mods/" + num.ToString() + "/thumb", text9);
                        num = -1;
                        break;
                    }

                    case "sign":
                    {
                        Console.WriteLine("WARNING: Signing data is the only method of authorization for AUDB. ONLY do this if Pastebin has manually asked you to, or you know EXACTLY what you are doing! NO EXCEPTIONS!");
                        Console.Write("anyway now that we've done that warning, what do you actually want to sign? (there's no confirmation so input it right the first time please) ");
                        string s        = Console.ReadLine();
                        byte[] inArray2 = rsacryptoServiceProvider.SignData(Encoding.ASCII.GetBytes(s), "SHA512");
                        string str2     = Convert.ToBase64String(inArray2);
                        Console.WriteLine("signature: " + str2);
                        break;
                    }

                    case "versions":
                    {
                        JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
                        string stringFromURL5    = AUDBTool.GetStringFromURL(webClient, "http://beestuff.pythonanywhere.com/keydb/api/keys");
                        List <KeyStructure> list = javaScriptSerializer.Deserialize <List <KeyStructure> >(stringFromURL5);
                        for (int i = 0; i < list.Count; i++)
                        {
                            KeyStructure keyStructure3 = list[i];
                            Console.WriteLine("KEY {0} ({1})", i, keyStructure3.metadata.name);
                            for (int j = 0; j < keyStructure3.audb.mods.Count; j++)
                            {
                                ModStructure modStructure = keyStructure3.audb.mods[j];
                                Console.WriteLine("{0} ({1}) - version {2}", j, modStructure.metadata.name, modStructure.version);
                            }
                        }
                        break;
                    }

                    case "hash":
                    {
                        Console.WriteLine("Warning: This is intended for Bee's use only, so it's quite unfriendly");
                        string filename = Console.ReadLine();
                        byte[] data     = File.ReadAllBytes(filename);
                        byte[] hash;
                        using (SHA512 shaM = new SHA512Managed())
                        {
                            hash = shaM.ComputeHash(data);
                        }
                        Console.WriteLine(Convert.ToBase64String(hash));
                        break;
                    }
                    }
                    if (flag3)
                    {
                        text = null;
                    }
                }
                catch (WebException ex)
                {
                    Console.WriteLine("ERROR RESPONSE:");
                    Console.WriteLine(new StreamReader(ex.Response.GetResponseStream()).ReadToEnd());
                }
            }
        }
コード例 #7
0
ファイル: keyboard.cs プロジェクト: Brave-cee/workplace
 private static extern int CallNextHookEx(int Hook, int nCode, int wParam, ref KeyStructure lParam);