public override void DropTable(IConnection connection) { EncryptImageDao dao = new EncryptImageDao(typeof(VersionOrigin)); dao.CurrentConnection = connection; dao.DropTable(); ++ModifiedCount; }
internal static void DeleteBy(Guid targetImageId) { EncryptImageDao dao = new EncryptImageDao(); dao.Delete(new Dictionary <string, object>() { { "TargetImageID", targetImageId } }); }
internal static EncryptImage FindBy(Guid targetImageId) { EncryptImageDao dao = new EncryptImageDao(); return(dao.FindBy(new Dictionary <string, object>() { { "TargetImageID", targetImageId } }).SingleOrDefault()); }
public override void CreateTable(IConnection connection) { EncryptImageDao dao = new EncryptImageDao(typeof(VersionOrigin)); dao.CurrentConnection = connection; dao.CreateTableIfNotExists(); ++ModifiedCount; dao.CreateIndexIfNotExists(); ++ModifiedCount; }
public static void Encrypt(ImageViewModel image, string OutFilePath, string password) { int len; byte[] buffer = new byte[4096]; string originalImagePath = image.AbsoluteMasterPath; using (FileStream outfs = new FileStream(OutFilePath, FileMode.Create, FileAccess.Write)) { using (AesManaged aes = new AesManaged()) { aes.BlockSize = 128; aes.KeySize = 128; aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.PKCS7; Rfc2898DeriveBytes deriveBytes = new Rfc2898DeriveBytes(password, 16); byte[] salt = new byte[16]; salt = deriveBytes.Salt; byte[] bufferKey = deriveBytes.GetBytes(16); aes.Key = bufferKey; aes.GenerateIV(); ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV); using (CryptoStream cse = new CryptoStream(outfs, encryptor, CryptoStreamMode.Write)) { outfs.Write(salt, 0, 16); outfs.Write(aes.IV, 0, 16); using (FileStream fs = new FileStream(originalImagePath, FileMode.Open, FileAccess.Read)) { while ((len = fs.Read(buffer, 0, 4096)) > 0) { cse.Write(buffer, 0, len); } } } } } EncryptImage encryptImage = new EncryptImage(); encryptImage.ID = Guid.NewGuid(); encryptImage.TargetImageID = image.ID; encryptImage.EncryptFilePath = OutFilePath; EncryptImageDao dao = new EncryptImageDao(); dao.InsertOrReplace(encryptImage); }
internal static bool AnyEncrypted() { EncryptImageDao dao = new EncryptImageDao(); return(dao.FindAll().Any()); }
public static IEnumerable <EncryptImage> FindAll() { EncryptImageDao dao = new EncryptImageDao(); return(dao.FindAll()); }