Exemplo n.º 1
0
        internal static string GetValueFromKey(string key, string value)
        {
            string result = "";

            if (key == null)
            {
                return("");
            }
            byte[] bytes = CryptoPrefsCreater.s_defaultEncoding.GetBytes(key);
            try
            {
                byte[] bytes2 = CryptoPrefsCreater.s_defaultEncoding.GetBytes(value);
                byte[] buffer = CryptoPrefsCreater.GetBuffer(bytes2.Length + CryptoPrefsCreater._aead.MaxOverhead);
                try
                {
                    ArraySegment <byte> arraySegment = CryptoPrefsCreater._aead.Encrypt(new ArraySegment <byte>(bytes2), bytes, buffer);
                    string text2 = Convert.ToBase64String(arraySegment.Array, arraySegment.Offset, arraySegment.Count);
                    result = text2;
                    return(result);
                }
                finally
                {
                    Array.Clear(buffer, 0, buffer.Length);
                }
            }
            catch (Exception)
            {
            }
            return(result);
        }
Exemplo n.º 2
0
        internal static string WrapKey(byte[] keyBytes)
        {
            byte[] buffer = CryptoPrefsCreater.GetBuffer(keyBytes.Length + CryptoPrefsCreater._aead.MaxOverhead);
            string result2;

            try
            {
                byte[] inArray = CryptoPrefsCreater._aesFacade.Encrypt(keyBytes);
                string text    = "AEAD:" + Convert.ToBase64String(inArray);
                result2 = text;
            }
            catch (Exception)
            {
                string text2 = Convert.ToBase64String(keyBytes);
                result2 = text2;
            }
            finally
            {
                Array.Clear(buffer, 0, buffer.Length);
            }
            return(result2);
        }
Exemplo n.º 3
0
 private void Encrypt_Click(object sender, EventArgs e)
 {
     EncryptKeyOut.Text   = Jformat(HttpUtility.UrlEncode(CryptoPrefsCreater.WrapKey(EncryptKeyIn.Text)));
     EncryptValueOut.Text = Jformat(HttpUtility.UrlEncode(CryptoPrefsCreater.GetValueFromKey(EncryptKeyIn.Text, EncryptValueIn.Text)));
     FullTextEnc.Text     = "<string name=\"" + EncryptKeyOut.Text + "\">" + EncryptValueOut.Text + "</string>";
 }
Exemplo n.º 4
0
 internal static string WrapKey(string key)
 {
     byte[] bytes = CryptoPrefsCreater.s_defaultEncoding.GetBytes(key);
     return(CryptoPrefsCreater.WrapKey(bytes));
 }