Пример #1
0
        public static CryptoResult_Text Decrypt(string text, string password, byte[] saltBytes)
        {
            CryptoResult_Text result = new CryptoResult_Text();
            result.Text = text;
            result.Done = false;

            if (string.IsNullOrEmpty(text))
                return result;

            if (string.IsNullOrEmpty(password))
                return result;

            byte[] data = Convert.FromBase64String(text);
            byte[] _password = Encoding.UTF8.GetBytes(password);

            _password = SHA256.Create().ComputeHash(_password);

            CryptoResult_Bytes _result = Decrypt(data, _password, saltBytes);
            if (!_result.Done)
                return result;

            result.Done = _result.Done;
            result.Text = Encoding.UTF8.GetString(_result.Bytes);

            return result;
        }
Пример #2
0
        public static CryptoResult_Text Encrypt(string text, string password, byte[] saltBytes)
        {
            CryptoResult_Text result = new CryptoResult_Text();
            result.Text = text;
            result.Done = false;

            if (string.IsNullOrEmpty(text))
                return result;

            if (string.IsNullOrEmpty(password))
                return result;

            byte[] data = Encoding.UTF8.GetBytes(text);
            byte[] _password = Encoding.UTF8.GetBytes(password);

            _password = SHA256.Create().ComputeHash(_password);

            CryptoResult_Bytes _result = Encrypt(data, _password, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 });
            if (!_result.Done)
                return result;

            result.Done = true;
            result.Text = Encoding.UTF8.GetString(_result.Bytes);

            return result;
        }