コード例 #1
0
ファイル: CPUKeyCheck.cs プロジェクト: ttgxdinger/Random
 internal static bool VerifyKey(string key)
 {
     _lastError = CPUKeyCheckErrors.Success;
     if (key.Length < 32) {
         _lastError = CPUKeyCheckErrors.TooShort;
         return false;
     }
     if (key.Length > 32) {
         _lastError = CPUKeyCheckErrors.TooLong;
         return false;
     }
     UInt64 tmp1, tmp2;
     if (!UInt64.TryParse(key.Substring(0, 16), NumberStyles.AllowHexSpecifier, null, out tmp1)) {
         _lastError = CPUKeyCheckErrors.BadKeyData1;
         return false;
     }
     if (!UInt64.TryParse(key.Substring(16), NumberStyles.AllowHexSpecifier, null, out tmp2)) {
         _lastError = CPUKeyCheckErrors.BadKeyData2;
         return false;
     }
     var hamming = CountBits(tmp1);
     hamming += CountBits(tmp2 & 0xFFFFFFFFFF030000);
     if (hamming != 53) {
         _lastError = CPUKeyCheckErrors.BadHamming;
         return false;
     }
     var keydata = Keytoarray(key);
     var keytmp = new byte[keydata.Length];
     Buffer.BlockCopy(keydata, 0, keytmp, 0, keydata.Length);
     if (!CalcCPUKeyECD(ref keytmp))
     {
         _lastError = CPUKeyCheckErrors.Unkown;
         return false;
     }
     if (!CompareByteArrays(keydata, keytmp)) {
         _lastError = CPUKeyCheckErrors.BadECD;
         return false;
     }
     return true;
 }