internal static string UnWrapKey(string key) { string key1 = key.Replace("AEAD:", "").Replace(" ", "+"); byte[] keyBytes = CryptoPrefsDecryptor.s_defaultEncoding.GetBytes(key1); byte[] buffer = CryptoPrefsDecryptor.GetBuffer(keyBytes.Length + CryptoPrefsDecryptor._aead.MaxOverhead); string result2; try { byte[] text = Convert.FromBase64String(key1); byte[] inArray = CryptoPrefsDecryptor._aesFacade.Decrypt(text); String result = Encoding.UTF8.GetString(inArray); result2 = result; } catch (Exception message) { string text2 = Convert.ToBase64String(keyBytes); result2 = message.StackTrace; } finally { Array.Clear(buffer, 0, buffer.Length); } return(result2); }
internal static string GetValueFromKey(string key, string value) { byte[] bytes = CryptoPrefsDecryptor.s_defaultEncoding.GetBytes(UnWrapKey(key)); string result; try { string @string = value; { byte[] array = Convert.FromBase64String(@string); { byte[] buffer = CryptoPrefsDecryptor.GetBuffer(array.Length - CryptoPrefsDecryptor._aead.MinOverhead); try { ArraySegment <byte> arraySegment = CryptoPrefsDecryptor._aead.Decrypt(new ArraySegment <byte>(array), bytes, buffer); string string2 = CryptoPrefsDecryptor.s_defaultEncoding.GetString(arraySegment.Array, arraySegment.Offset, arraySegment.Count); result = string2; } finally { Array.Clear(buffer, 0, buffer.Length); } } } } catch (Exception message) { result = message.StackTrace; } return(result); }
private void Decrypt_Click(object sender, EventArgs e) { DecryptKeyOut.Text = CryptoPrefsDecryptor.UnWrapKey(HttpUtility.UrlDecode(DecryptKeyIn.Text)); DecryptValueOut.Text = CryptoPrefsDecryptor.GetValueFromKey(HttpUtility.UrlDecode(DecryptKeyIn.Text), HttpUtility.UrlDecode(DecryptValueIn.Text)); FullTextDec.Text = "<string name=\"" + DecryptKeyOut.Text + "\">" + DecryptValueOut.Text + "</string>"; }