public static void DecryptDatabase() { //механизм расшифровки Encoding ANSI = Encoding.GetEncoding(1252); StreamReader sr = new StreamReader(DataBasePath, ANSI); string sourcefile = sr.ReadToEnd(); sr.Close(); byte[] key = ANSI.GetBytes(CryptoKey); RC4 decoder = new RC4(key); byte[] SourceBytes = ANSI.GetBytes(sourcefile); byte[] decryptedBytes = decoder.Decode(SourceBytes, SourceBytes.Length); string decryptedString = ANSI.GetString(decryptedBytes); StreamWriter sw = new StreamWriter(@"db/mirage.db", false, ANSI); sw.WriteLine(decryptedString); sw.Close(); }
public static void EncryptDatabase() { //механизм шифрования Encoding ANSI = Encoding.GetEncoding(1252); StreamReader sr = new StreamReader(DataBasePath, ANSI); string sourcefile = sr.ReadToEnd(); sr.Close(); byte[] key = ANSI.GetBytes(CryptoKey); //процесс шифрования RC4 encoder = new RC4(key); byte[] SourceBytes = ANSI.GetBytes(sourcefile); byte[] result = encoder.Encode(SourceBytes, SourceBytes.Length); string encryptedString = ANSI.GetString(result); StreamWriter sw = new StreamWriter(@"db/mirage.db", false, ANSI); sw.WriteLine(encryptedString); sw.Close(); }