コード例 #1
0
        public override void DropTable(IConnection connection)
        {
            EncryptImageDao dao = new EncryptImageDao(typeof(VersionOrigin));

            dao.CurrentConnection = connection;
            dao.DropTable();
            ++ModifiedCount;
        }
コード例 #2
0
        internal static void DeleteBy(Guid targetImageId)
        {
            EncryptImageDao dao = new EncryptImageDao();

            dao.Delete(new Dictionary <string, object>()
            {
                { "TargetImageID", targetImageId }
            });
        }
コード例 #3
0
        internal static EncryptImage FindBy(Guid targetImageId)
        {
            EncryptImageDao dao = new EncryptImageDao();

            return(dao.FindBy(new Dictionary <string, object>()
            {
                { "TargetImageID", targetImageId }
            }).SingleOrDefault());
        }
コード例 #4
0
        public override void CreateTable(IConnection connection)
        {
            EncryptImageDao dao = new EncryptImageDao(typeof(VersionOrigin));

            dao.CurrentConnection = connection;
            dao.CreateTableIfNotExists();
            ++ModifiedCount;
            dao.CreateIndexIfNotExists();
            ++ModifiedCount;
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        internal static bool AnyEncrypted()
        {
            EncryptImageDao dao = new EncryptImageDao();

            return(dao.FindAll().Any());
        }
コード例 #7
0
        public static IEnumerable <EncryptImage> FindAll()
        {
            EncryptImageDao dao = new EncryptImageDao();

            return(dao.FindAll());
        }