Exemplo n.º 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);
        }
Exemplo n.º 2
0
        private static void EncryptAndSetChars(char[] val, SerializedProperty prop, char[] key)
        {
            var encrypted = ObscuredString.InternalEncryptDecrypt(val, key);

            SetChars(prop, encrypted);
        }