private static bool CheckFileEntry(TamperDetectionFileEntry entry)
        {
            string[] files = Directory.GetFiles(entry.rootSearchPath, entry.filename, entry.mustBeExact ? SearchOption.TopDirectoryOnly : SearchOption.AllDirectories);

            if (files.Length == 0)
            {
                Debug.LogError(string.Format("File ({0}) not found in folder ({1})", entry.filename, entry.rootSearchPath));
                return(false);
            }
            //Debug.Log(string.Format("File ({0}) found in folder ({1})", entry.filename, entry.rootSearchPath));

            byte[] hash   = _HashProvider.ComputeHash(File.OpenRead(files[0]));
            bool   result = MixCastCryptoUtils.BytesEqual(hash, entry.hash);

            if (!result)
            {
#if UNITY_EDITOR
                Debug.LogError(string.Format("hash mismatch: {0}, expected {1} got {2}",
                                             entry.filename, Convert.ToBase64String(entry.hash), Convert.ToBase64String(hash)));
#else
                Debug.LogError("file change detected: " + files[0]);
#endif
            }
            return(result);
        }
Beispiel #2
0
        private static bool IsSameComputer(MixCastData.SecureData data, MachineId machineId)
        {
            if (machineId == null || data == null || string.IsNullOrEmpty(data.machineId))
            {
                return(false);
            }

            return(MixCastCryptoUtils.BytesEqual(
                       machineId.ComputeHash(),
                       Convert.FromBase64String(data.machineId)));
        }
Beispiel #3
0
        public static bool KeysAreCompatible(byte[] publicKey, byte[] privateKey)
        {
            if (publicKey == null || privateKey == null)
            {
                return(false);
            }

            MixCastEncrypter encrypter = new MixCastEncrypter(publicKey);
            MixCastDecrypter decrypter = new MixCastDecrypter(privateKey);

            byte[] testData  = { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9 };
            byte[] encrypted = encrypter.Encrypt(testData);
            byte[] decrypted = decrypter.Decrypt(encrypted);

            if (!MixCastCryptoUtils.BytesEqual(testData, decrypted))
            {
                return(false);
            }

            return(true);
        }
 public byte[] Decrypt(byte[] data)
 {
     return(MixCastCryptoUtils.ProcessCipher(data, _Cipher));
 }