public static SecurityValue Create(byte[] inData) { SecurityValue value = new SecurityValue(); value.SetValue(inData); return(value); }
/// <summary> /// 데이터를 바이트 배열로 변환하여 저장 /// </summary> /// <typeparam name="T">타입</typeparam> /// <param name="inKey">키</param> /// <param name="inData">저장할 데이터</param> private void SetByte <T>(string inKey, byte[] inData) { Type type = typeof(T); if (!_securityKeyDic.ContainsKey(type)) { return; } if (_securityKeyDic[type].ContainsKey(inKey)) { _securityKeyDic[type][inKey].SetValue(inData); } else { _securityKeyDic[type].Add(inKey, SecurityValue.Create(inData)); } }
/// <summary> /// 데이터 기록 /// </summary> /// <typeparam name="T">타입</typeparam> /// <param name="key">키</param> /// <param name="value">데이터</param> public void Set <T>(string key, object value) where T : IConvertible { System.Type type = typeof(T); byte[] byteArr = null; if (type == typeof(bool)) { byteArr = BitConverter.GetBytes((bool)value); } else if (type == typeof(short)) { byteArr = BitConverter.GetBytes((short)value); } else if (type == typeof(ushort)) { byteArr = BitConverter.GetBytes((ushort)value); } else if (type == typeof(int)) { byteArr = BitConverter.GetBytes((int)value); } else if (type == typeof(uint)) { byteArr = BitConverter.GetBytes((uint)value); } else if (type == typeof(long)) { byteArr = BitConverter.GetBytes((long)value); } else if (type == typeof(ulong)) { byteArr = BitConverter.GetBytes((ulong)value); } else if (type == typeof(float)) { byteArr = BitConverter.GetBytes((float)value); } else if (type == typeof(double)) { byteArr = BitConverter.GetBytes((double)value); } else if (type == typeof(char)) { byteArr = BitConverter.GetBytes((char)value); } else if (type == typeof(string)) { if (_strKeyDic.ContainsKey(key)) { _strKeyDic[key].Set(key, (string)value); } else { _strKeyDic.Add(key, new SecurityString(key, (string)value)); } return; } else { UnityEngine.Debug.Log(string.Format("{0} 타입은 암호화할 수 없습니다.", type)); return; } if (!_securityKeyDic.ContainsKey(type)) { _securityKeyDic.Add(type, new Dictionary <string, SecurityValue>()); } if (_securityKeyDic[type].ContainsKey(key)) { _securityKeyDic[type][key].SetValue(byteArr); } else { _securityKeyDic[type].Add(key, SecurityValue.Create(byteArr)); } }