コード例 #1
0
        //Метод декриптования файла ключа
        //Возвращает true или false в зависимости от того,
        //совпал ли ключ в файле и входная строка
        public bool DecodeKey(string inString, string path)
        {
            string decryptstring = null;

            byte[] key = new byte[0x20];
            for (int i = 0; i <= 0x1f; i++)
            {
                key[i] = 0x1f;
            }
            Rijndael.Key = key;
            using (FileStream fs = File.Open(path, FileMode.Open))
            {
                //FileStream fs = new FileStream(path, FileMode.Open);
                byte[] IV = new byte[Rijndael.IV.Length];
                fs.Read(IV, 0, IV.Length);
                Rijndael.IV = IV;
                ICryptoTransform transformer = Rijndael.CreateDecryptor();
                CryptoStream     cs          = new CryptoStream(fs, transformer, CryptoStreamMode.Read);
                StreamReader     sr          = new StreamReader(cs);
                decryptstring = sr.ReadToEnd();

                CryptoClass crypto = new CryptoClass();

                decryptstring = decryptstring.Substring(0, decryptstring.IndexOf("|"));

                if (!(decryptstring == inString))
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: dark567/ExportPriceForWeb
        private static void LicensyaCheck()
        {
            string curFile = @"keyfile.dat";

            if (!File.Exists(curFile))
            {
                Environment.Exit(0);
            }
            ;

            CryptoClass crypto = new CryptoClass();
            string      date   = crypto.GetDecodeKey(curFile).Substring(crypto.GetDecodeKey("keyfile.dat").IndexOf("|") + 1);

            if (DateTime.Parse(date).AddDays(1) <= DateTime.Now)
            {
                try
                {
                    if (File.Exists(curFile))
                    {
                        File.Delete(curFile);
                    }
                }
                catch (IOException) { }
            }