Jump to content
¯\_( ツ)_/¯
  • TAD GROUP are currently hiring penetration testers. Please read the topic in Career Central subforum.
  • Sponsored Ad
ТУК НЕ СЕ ПРЕДЛАГАТ ХАКЕРСКИ УСЛУГИ ! ×

DemonaWeBace

Members
  • Content Count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral

About DemonaWeBace

  • Rank
    User
  1. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Security.Cryptography; using System.Runtime.InteropServices; namespace DarkSoft.OS.SecurityModel { public class FileSecurity { public void FileSecurtiy() { } protected byte[] retEncFReq(byte[] cont, byte[] pwd) { byte[] endResult = null; byte[] salt = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; using (MemoryStream ms = new MemoryStream()) { using (RijndaelManaged alg = new RijndaelManaged()) { alg.KeySize = 256; alg.BlockSize = 128; var key = new Rfc2898DeriveBytes(pwd, salt, 1000); alg.Key = key.GetBytes(alg.KeySize / 8); alg.IV = key.GetBytes(alg.BlockSize / 8); alg.Mode = CipherMode.CBC; using (CryptoStream cs = new CryptoStream(ms, alg.CreateEncryptor(), CryptoStreamMode.Write)) { cs.Write(cont, 0, cont.Length); cs.Close(); } } endResult = ms.ToArray(); } return endResult; } protected byte[] retDecFReq(byte[] cont, byte[] pwd) { byte[] endResult = null; byte[] salt = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; using (MemoryStream ms = new MemoryStream()) { using (RijndaelManaged alg = new RijndaelManaged()) { alg.KeySize = 256; alg.BlockSize = 128; var key = new Rfc2898DeriveBytes(pwd, salt, 1000); alg.Key = key.GetBytes(alg.KeySize / 8); alg.IV = key.GetBytes(alg.BlockSize / 8); alg.Mode = CipherMode.CBC; using (CryptoStream cs = new CryptoStream(ms, alg.CreateDecryptor(), CryptoStreamMode.Write)) { cs.Write(cont, 0, cont.Length); cs.Close(); } } endResult = ms.ToArray(); } return endResult; } public string retEncTReq(string cont, byte[] passWord) { byte[] cipherText = null; string cipHerText = null; byte[] salt = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; using (MemoryStream ms = new MemoryStream()) { using (RijndaelManaged alg = new RijndaelManaged()) { alg.KeySize = 256; alg.BlockSize = 128; var key = new Rfc2898DeriveBytes(passWord, salt, 1000); alg.Key = key.GetBytes(alg.KeySize / 8); alg.IV = key.GetBytes(alg.BlockSize / 8); alg.Mode = CipherMode.CBC; using (MemoryStream msEncrypt = new MemoryStream()) { using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, alg.CreateEncryptor(), CryptoStreamMode.Write)) { using (StreamWriter swEncrypt = new StreamWriter(csEncrypt)) { swEncrypt.Write(cont); } cipherText = msEncrypt.ToArray(); } } } } return Convert.ToBase64String(cipherText); } public string retDecTReq(byte[] cont, byte[] passWord) { byte[] cipherText = null; string cipHerText = null; byte[] salt = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; using (MemoryStream ms = new MemoryStream(cont)) { using (RijndaelManaged alg = new RijndaelManaged()) { alg.KeySize = 256; alg.BlockSize = 128; var key = new Rfc2898DeriveBytes(passWord, salt, 1000); alg.Key = key.GetBytes(alg.KeySize / 8); alg.IV = key.GetBytes(alg.BlockSize / 8); alg.Mode = CipherMode.CBC; using (MemoryStream msDecrypt = new MemoryStream(cont)) { using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, alg.CreateDecryptor(), CryptoStreamMode.Read)) { using (StreamReader srDecrypt = new StreamReader(csDecrypt)) { cipHerText = srDecrypt.ReadToEnd(); } } } } } return cipHerText; } public string encText(string text, string password) { byte[] pwd = Encoding.UTF8.GetBytes(password); pwd = SHA512.Create().ComputeHash(pwd); string btsEncrypted = retEncTReq(text, pwd); return btsEncrypted; } public string decText(string text, string password) { byte[] cont = Convert.FromBase64String(text); byte[] pwd = Encoding.UTF8.GetBytes(password); pwd = SHA512.Create().ComputeHash(pwd); string btsEncrypted = retDecTReq(cont, pwd); return btsEncrypted; } public void decFile(string file, string password) { byte[] bytesToBeDecrypted = File.ReadAllBytes(file); byte[] passwordBytes = Encoding.UTF8.GetBytes(password); passwordBytes = SHA512.Create().ComputeHash(passwordBytes); byte[] bytesDecrypted = retDecFReq(bytesToBeDecrypted, passwordBytes); File.WriteAllBytes(file, bytesDecrypted); string extension = System.IO.Path.GetExtension(file); string result = file.Substring(0, file.Length - extension.Length); System.IO.File.Move(file, result); } public void encFile(string file, string password, string extension) { byte[] bytesToBeEncrypted = File.ReadAllBytes(file); byte[] passwordBytes = Encoding.UTF8.GetBytes(password); passwordBytes = SHA512.Create().ComputeHash(passwordBytes); byte[] bytesEncrypted = retEncFReq(bytesToBeEncrypted, passwordBytes); File.WriteAllBytes(file, bytesEncrypted); System.IO.File.Move(file, file + extension); } public string getFileChecksum(string filename) { using (SHA512Cng md5check = new SHA512Cng()) { using (var stream = File.OpenRead(filename)) { ConvertType cngInfo = new ConvertType(); return cngInfo.byteArrayToString(md5check.ComputeHash(stream)); } } } public bool isFileHashMatches(string filename, string hash) { string fileHash = getFileChecksum(filename); if (hash.Length == fileHash.Length && hash == fileHash) { return true; } else { return false; } } public string calculateHash_SHA512(string text) { byte[] tmp = Encoding.ASCII.GetBytes(text); using (SHA512Cng shaCalc = new SHA512Cng()) { ConvertType cngInfo = new ConvertType(); return cngInfo.byteArrayToString(shaCalc.ComputeHash(tmp)); } } public bool isCalculateHashMatches(string origtext, string currentHash) { string origHash = calculateHash_SHA512(origtext); if (currentHash == origHash && currentHash.Length == origtext.Length) { return true; } else { return false; } } } public class ConvertType { public string byteArrayToString(byte[] array) { int i; StringBuilder sOutput = new StringBuilder(array.Length); for (i = 0; i < array.Length - 1; i++) { sOutput.Append(array[i].ToString("X2")); } return sOutput.ToString(); } public string stringArrayToString(string[] arraystr) { StringBuilder result = new StringBuilder(); foreach (string value in arraystr) { result.Append(value); result.Append(' '); } return result.ToString(); } } } Дайте оценка от 1 до 10 на тази защита. Ако има нещо да се променя кажете ми. Благодаря предварително.
  2. Кракни това: A35C5B2538D0AFBB08F9B4277EAA46648713F6C938142A4BDB - SHA 512 Cng
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.