10 개의 IP 주소를 저장해야하는 C# 응용 프로그램을 구현 중입니다. 그래서 응용 프로그램에 데이터베이스를 통합하면 자원 낭비라고 생각합니다. 나는 그 주소가 안전해야하기 때문에 XML이나 텍스트 파일을 사용할 수 없다. 나는 내 자신의 파일 형식을 구현하고 그것을 사용하도록 제안했다.
1. 별도의 파일 형식을 대신 구현하는 방법이 있습니까?
2. 새 파일 형식을 구현하는 방법이없고 무엇이 가장 좋은지 확인하십시오.데이터베이스없이 데이터를 영구 저장하십시오.
1
A
답변
2
1
암호화 된 데이터가 안전하지 않을 위험이 없으면 Salt를 적용하고 Text File 또는 Xml에 저장하십시오.
이 샘플을 참조하십시오using System.Security.Cryptography;
public static string EncodePasswordToBase64(string password)
{ byte[] bytes = Encoding.Unicode.GetBytes(password);
byte[] inArray = HashAlgorithm.Create("SHA1").ComputeHash(bytes);
return Convert.ToBase64String(inArray);
}
해싱이 방법의 문자열을 envcrypt하는 SHA1를 사용하여 적용됩니다.
2
1
암호화 문자열로 물건을 유지하려는 경우. 여기에 내가 사용하는 두 가지 방법. 그것은 강력하게 암호화하고 또한 그것에 소금을 추가합니다.
public static string EncryptString(string sData, string sKey)
{
// instance of the Rihndael.
RijndaelManaged RijndaelManagedCipher = new RijndaelManaged();
// string to byte array.
byte[] UnicodeText = System.Text.Encoding.Unicode.GetBytes(sData);
// adign dirt to the string to make it harder to guess using a dictionary attack.
byte[] Dirty = Encoding.ASCII.GetBytes(sKey.Length.ToString());
// The Key will be generated from the specified Key and dirt.
PasswordDeriveBytes FinalKey = new PasswordDeriveBytes(sKey, Dirty);
// Create a encryptor from the existing FinalKey bytes.
ICryptoTransform Encryptor = RijndaelManagedCipher.CreateEncryptor(FinalKey.GetBytes(32), FinalKey.GetBytes(16));
// Create a MemoryStream that is going to hold the encrypted bytes
MemoryStream memoryStream = new MemoryStream();
// Create a CryptoStream
CryptoStream cryptoStream = new CryptoStream(memoryStream, Encryptor, CryptoStreamMode.Write);
// write the encryption
cryptoStream.Write(UnicodeText, 0, UnicodeText.Length);
// write final blocks to the memory stream
cryptoStream.FlushFinalBlock();
// Convert to byte array the encrypted data
byte[] CipherBytes = memoryStream.ToArray();
// Close streams.
memoryStream.Close();
cryptoStream.Close();
// Convert to byte array to string
string EncryptedData = Convert.ToBase64String(CipherBytes);
// Return the encrypted string
return EncryptedData;
}
public static string DecryptString(string sData, string sKey)
{
// instance of rijndael
RijndaelManaged RijndaelCipher = new RijndaelManaged();
// convert to byte aray the encrypted data
byte[] EncryptedData = Convert.FromBase64String(sData);
// add dirt to the key like when encrypthing
byte[] Dirty = Encoding.ASCII.GetBytes(sKey.Length.ToString());
// get the finalkey o be used
PasswordDeriveBytes FinalKey = new PasswordDeriveBytes(sKey, Dirty);
// Create a decryptor with the key
ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(FinalKey.GetBytes(32), FinalKey.GetBytes(16));
// load to memory stream the encrypted data
MemoryStream memoryStream = new MemoryStream(EncryptedData);
// Create a CryptoStream on the memory stream holding the data
CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read);
// Length is unknown but need placeholder big enought for decrypted data
// we know the decrypted version cannot ever be longer than the crypted version
// since we added bunch of garbage to it so the length of encrypted data is safe to use
byte[] UnicodeText = new byte[EncryptedData.Length];
// Start decrypting
int DecryptedCount = cryptoStream.Read(UnicodeText, 0, UnicodeText.Length);
//close streams
memoryStream.Close();
cryptoStream.Close();
// load decrypted data to string
string DecryptedData = Encoding.Unicode.GetString(UnicodeText, 0, DecryptedCount);
// Return decrypted string
return DecryptedData;
}
에 추가이
이제 단순히
public class Settings
{
public const string EncryptionKey = "somekey";
public List<string> IP = new List<string>();
public string getClassEncrypted()
{
return EncryptString(new JavaScriptSerializer().Serialize(this), EncryptionKey);
}
public Settings getClassDecrypted(string sClassEcrypted)
{
return new JavaScriptSerializer().Deserialize<Settings>(DecryptString(sClassEcrypted, EncryptionKey));
}
}
하나 IP를 같은 클래스는 단지 파일 Settings.getClassEncrypted();
하고 시간이 때 다음 얻기 위해 쓰기로 설정되어 있는지 확인 값을 다시 텍스트 파일을 읽고이 같은 무언가로 다시로드하십시오 :
string sFileText = ...; // from the file saved
var setting = new Settings.getClassDecrypted(sFileText);
이제 모든 수업을 들으셔야합니다. 그리고 클래스도 직렬화됩니다.
관련 문제
- 1. iOS 기기에 데이터를 영구 저장하십시오.
- 2. 공급자에 저장된 데이터를 영구 저장하십시오.
- 3. 변수에 데이터를 영구 저장하십시오. (자바 스크립트)
- 4. 데이터베이스없이 데이터를 수집하는 방법
- 5. 영구 (사용자) 데이터에 NSArray를 저장하십시오.
- 6. 데이터베이스없이 데이터를 관리하는 방법은 무엇입니까?
- 7. 데이터베이스없이 WiFi를 통해 데이터를 전송
- 8. 안드로이드에서 공유 환경 설정없이 데이터베이스없이 arrayList를 영구 저장하는 방법은 무엇입니까?
- 9. python/junit 테스트 결과를 데이터베이스에 영구 저장하십시오.
- 10. 데이터베이스없이 asp.net을 사용하여 격자보기에 데이터를 삽입하는 방법
- 11. 임시 데이터를 couchbase 또는 redis에 저장하십시오.
- 12. 문제는 에뮬레이터에서 영구 데이터를
- 13. 구조체 inode에 데이터를 저장하십시오.
- 14. 세션을 통해 데이터를 저장하십시오.
- 15. 데이터를 로컬에 저장하십시오.
- 16. excel 데이터를 couchDB에 저장하십시오.
- 17. jQuery.POST에서 응답받은 데이터를 저장하십시오.
- 18. 공간 데이터를 계산하거나 저장하십시오.
- 19. 안드로이드에서 주기적으로 데이터를 저장하십시오.
- 20. 데이터를 HTML 파일에 저장하십시오.
- 21. 중복 데이터를 cassandra에 저장하십시오.
- 22. mysql 데이터를 배열에 저장하십시오
- 23. UITableView에서 현재 데이터를 저장하십시오.
- 24. 고객 데이터를 Paypal에 저장하십시오.
- 25. DataGrid의 데이터를 데이터베이스에 저장하십시오.
- 26. 데이터를 txt로 저장하십시오.
- 27. 콜 데이터베이스없이 gridview 정렬
- 28. 영구 데이터를 정렬하는 방법은 무엇입니까?
- 29. plist에 데이터를 영구 저장하는 방법
- 30. 사용자 데이터를 영구 저장하는 방법
포함 된 리소스로 설정이나 파일에 저장하지 않는 이유는 무엇입니까? 암호화/암호 해독 작업도 만들 수 있습니다. – CuriousPen
고맙습니다. – Sandaru