示例#1
0
        internal static bool MigrateObscuredStringIfNecessary(SerializedProperty sp)
        {
            var hiddenValueProperty = sp.FindPropertyRelative("hiddenValue");

            if (hiddenValueProperty == null || hiddenValueProperty.arraySize == 0)
            {
                return(false);
            }

            var currentCryptoKeyOldProperty = sp.FindPropertyRelative("currentCryptoKey");

            if (currentCryptoKeyOldProperty == null)
            {
                return(false);
            }

            var currentCryptoKeyOld = currentCryptoKeyOldProperty.stringValue;

            if (string.IsNullOrEmpty(currentCryptoKeyOld))
            {
                return(false);
            }

            var hiddenCharsProperty = sp.FindPropertyRelative("hiddenChars");

            if (hiddenCharsProperty == null || hiddenCharsProperty.arraySize == 0)
            {
                return(false);
            }

            var hiddenValue = ObscuredStringDrawer.GetBytesObsolete(hiddenValueProperty);

            var decrypted = ObscuredString.EncryptDecryptObsolete(ObscuredString.GetStringObsolete(hiddenValue), currentCryptoKeyOld);

            var currentCryptoKey = ObscuredString.GenerateKey();
            var hiddenChars      = ObscuredString.InternalEncryptDecrypt(decrypted.ToCharArray(), currentCryptoKey);


            ObscuredStringDrawer.SetChars(hiddenCharsProperty, hiddenChars);
            var currentCryptoKeyProperty = sp.FindPropertyRelative("cryptoKey");

            ObscuredStringDrawer.SetChars(currentCryptoKeyProperty, currentCryptoKey);

            hiddenValueProperty.arraySize           = 0;
            currentCryptoKeyOldProperty.stringValue = null;

            return(true);
        }