Exemple #1
0
        static void RawFileMovetoEncrypt()
        {
            PGPLib pgp                = new PGPLib();
            bool   asciiArmor         = false;
            bool   withIntegrityCheck = false;
            string sourcePath         = @"C:\DATA FILES\Raw Data Files\";
            string targetPath         = @"C:\DATA FILES\Encrypted Data Files\";
            string fileName           = "";
            int    fileSize;
            string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
            string destFile   = System.IO.Path.Combine(targetPath, fileName);

            if (System.IO.Directory.Exists(sourcePath))
            {
                string[] files = System.IO.Directory.GetFiles(sourcePath);

                // Copy the files and overwrite destination files if they already exist.
                foreach (string s in files)
                {
                    // Use static Path methods to extract only the file name from the path.
                    fileName = System.IO.Path.GetFileName(s);
                    pgp.EncryptFile(sourcePath + fileName,
                                    @"C:\DATA FILES\publickey.asc",
                                    targetPath + fileName,
                                    asciiArmor,
                                    withIntegrityCheck);
                    // destFile = System.IO.Path.Combine(targetPath, fileName);
                    // System.IO.File.Copy(s, destFile, true);
                }
            }


            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                CloudConfigurationManager.GetSetting("StorageConnectionString"));
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            //encryptedtgblfiles
            CloudBlobContainer container = blobClient.GetContainerReference("encryptedtgblfiles");

            if (System.IO.Directory.Exists(sourcePath))
            {
                string[] files = System.IO.Directory.GetFiles(sourcePath);

                // Copy the files and overwrite destination files if they already exist.
                foreach (string s in files)
                {
                    fileName = System.IO.Path.GetFileName(s);
                    CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);
                    fileSize = fileName.Length;
                    // Create or overwrite the "myblob" blob with contents from a local file.
                    using (var fileStream = System.IO.File.OpenRead(targetPath + fileName))
                    {
                        blockBlob.UploadFromStream(fileStream);
                    }

                    // To move a file or folder to a new location:
                    //  logger(fileName, "Uploaded",fileSize);

                    // To move an entire directory. To programmatically modify or combine
                    // path strings, use the System.IO.Path class.
                    //System.IO.Directory.Move(@"C:\Users\Public\public\test\", @"C:\Users\Public\private");
                }
            }
        }
 /// <summary>
 /// Method to encrypt a file.
 /// </summary>
 /// <param name="fileToEncrypt">File containing the data to be encrypted.</param>
 /// <param name="publicKeyFile">File containing the public key.</param>
 /// <param name="encryptedFile">Output file containing encrypted data.</param>
 /// <param name="asciiArmor">Should the encrypted file be in ASCII Armored format. If false the encrypted file is in binary format.</param>
 /// <param name="withIntegrityCheck">Should integrity check information be added to the encrypted file.</param>
 public void EncryptFile(string fileToEncrypt, string publicKeyFile, string encryptedFile, bool asciiArmor, bool withIntegrityCheck)
 {
     _pgp.EncryptFile(new FileInfo(fileToEncrypt), new FileInfo(publicKeyFile), new FileInfo(encryptedFile), asciiArmor, withIntegrityCheck);
 }