Created
May 19, 2018 08:47
-
-
Save pawlos/8273c8f4441d7563b60733bbd84eb1e8 to your computer and use it in GitHub Desktop.
C# program for decoding encrypted database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.IO; | |
| using System.Security.Cryptography; | |
| namespace ConsoleApp1 | |
| { | |
| class Program | |
| { | |
| private static string GeneratePassword(DateTime dt) => ((int)dt.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString(); | |
| private static byte[] CreateKey(string password, int keyBytes = 32) => new Rfc2898DeriveBytes(password, Salt, 300).GetBytes(keyBytes); | |
| private static readonly byte[] Salt = new byte[] {10,20,30,40,50,60,70,80}; | |
| static void Main(string[] args) | |
| { | |
| string filename = "dbname.db.enc"; | |
| if (!File.Exists(filename)) | |
| { | |
| Console.WriteLine("No such file!"); | |
| Environment.Exit(-111); | |
| } | |
| string d = File.ReadAllText(filename); | |
| byte[] array = Convert.FromBase64String(d); | |
| DateTime dt = new DateTime(2018, 05, 14, 0, 0, 0); | |
| DateTime maxDate = new DateTime(2018, 05, 16, 20, 0, 0); | |
| do | |
| { | |
| try | |
| { | |
| if (dt > maxDate) | |
| { | |
| Console.WriteLine("Reached the min date"); | |
| break; | |
| } | |
| string text = "GeronimoAlpha" + GeneratePassword(dt); | |
| RijndaelManaged rijndaelManaged = new RijndaelManaged(); | |
| rijndaelManaged.Key = CreateKey(text, 32); | |
| rijndaelManaged.IV = new byte[] { 0x18, 0x15, 0x4F, 0x9A, 0x4C, 0xBD, 0x15, 0x40, 0xE2, 0xB5, 0x43, 0x1E, 0x66, 0x68, 0x14, 0x04 }; | |
| using (MemoryStream msDecrypt = new MemoryStream(array)) | |
| { | |
| ICryptoTransform transform = rijndaelManaged.CreateDecryptor(); | |
| using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, transform, CryptoStreamMode.Read)) | |
| { | |
| using (MemoryStream srDecrypt = new MemoryStream()) | |
| { | |
| csDecrypt.CopyTo(srDecrypt); | |
| File.WriteAllBytes("dbname." + text + ".db", srDecrypt.ToArray()); | |
| } | |
| } | |
| } | |
| } | |
| catch (CryptographicException) | |
| { | |
| //continue | |
| } | |
| finally | |
| { | |
| dt = dt.AddSeconds(1); | |
| } | |
| } | |
| while (true); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment