Support for Binary Keys

This commit is contained in:
Jim Norman
2005-12-09 16:16:58 +00:00
parent 8b8d606aa3
commit c30b2b3195
5 changed files with 73 additions and 4 deletions

View File

@@ -8,6 +8,11 @@ namespace sscs.cache
{
public class KeyValue
{
public static int VALUE_TYPE_STRING = 0;
public static int VALUE_TYPE_BINARY = 1;
private int m_iValueType = VALUE_TYPE_STRING;
private string m_key;
public string Key
{
@@ -27,6 +32,12 @@ namespace sscs.cache
return (DecryptValue());
}
public byte[] GetValueAsBytes()
{
return (DecyptValueAsBytes());
}
// this sets string values
public void SetValue(string sValue)
{
@@ -42,6 +53,14 @@ namespace sscs.cache
}
}
// this sets binary values
public void SetValue(byte[] baValue)
{
m_iValueType = VALUE_TYPE_BINARY;
m_value = EncryptValue(baValue);
m_modified = DateTime.Now;
}
/*
public string Value
{
@@ -119,17 +138,36 @@ namespace sscs.cache
m_value = EncryptValue(sValue);
}
public KeyValue(string sKey, byte[] baValue)
{
// NOTE: Order is important, do not change
m_created = m_modified = DateTime.Now;
m_key = sKey;
m_value = EncryptValue(baValue);
m_iValueType = VALUE_TYPE_BINARY;
}
private byte[] EncryptValue(string sValue)
{
byte[] baValueClear = Encoding.Default.GetBytes(sValue);
return (XORValue(baValueClear));
return EncryptValue(baValueClear);
}
private byte[] EncryptValue(byte[] baValueClear)
{
return (XORValue(baValueClear));
}
private string DecryptValue()
{
byte[] baValueClear = XORValue(m_value);
byte[] baValueClear = DecyptValueAsBytes();
return Encoding.Default.GetString(baValueClear);
}
private byte[] DecyptValueAsBytes()
{
return XORValue(m_value);
}
private byte[] XORValue(byte[] baInput)
{
@@ -145,6 +183,11 @@ namespace sscs.cache
return baOutput;
}
public int GetValueType()
{
return m_iValueType;
}
public string ToXML()
{
StringBuilder sb = new StringBuilder();