Esempio n. 1
0
        public void B2UploadTest()
        {
            BUCommon.AccountList accts = BackupLib.AccountBuilder.BuildAccounts();
            var acct = accts.accounts.FirstOrDefault();

            Assert.AreEqual("CommB2.Connection", acct.svcName);
            acct.service.authorize();

            var cont = acct.service.getContainers().FirstOrDefault();

            Assert.IsNotNull(cont);
            string srcfile = "c:\\tmp\\photos\\2016\\1231-newyears\\DSC06562.ARW";
            var    ff      = new BUCommon.FreezeFile {
                path = "2016/1231-newyears/DSC06562.ARW"
            };

            var rsa     = BackupLib.KeyLoader.LoadRSAKey("c:\\tmp\\id_rsa_1_pub");
            var fe      = new BackupLib.FileEncrypt(rsa);
            var fs      = ff.readStream("c:\\tmp\\photos");
            var encstrm = fe.encrypt(fs);
            var sha1    = System.Security.Cryptography.SHA1Cng.Create();

            var res = sha1.ComputeHash(encstrm);

            encstrm.Seek(0, System.IO.SeekOrigin.Begin);

            DateTime now = DateTime.Now;
            var      td  = acct.service.threadStart();

            acct.service.uploadFile(td, cont, ff, encstrm, null);
            acct.service.threadStop(td);
            Assert.AreEqual(2017, ff.uploaded.Year);
            Assert.AreEqual(now.Month, ff.uploaded.Month);
            Assert.AreEqual(now.Day, ff.uploaded.Day);
        }
Esempio n. 2
0
        public void TestFileEncrypt()
        {
            var rsa = _loadRSA(Encrypting._PUBKEY);

            BackupLib.FileEncrypt enc = new BackupLib.FileEncrypt(rsa);
            //var srcfile = new FileStream("c:\\tmp\\foo.txt"/*"c:\\temp\\dumps\\ttirdreport.20170116_134248.xml"*/, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            var srcfile  = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(Encrypting._PUBKEY));
            var encbytes = enc.encrypt(srcfile);

            /* persist the encrypted file. */
            var destfile = new FileStream("c:\\tmp\\encfile.enc", FileMode.Create, FileAccess.ReadWrite, FileShare.Read);

            encbytes.WriteTo(destfile);
            destfile.Flush();
            encbytes.Seek(0, SeekOrigin.Begin);

            destfile.Dispose();

            var b64 = Convert.ToBase64String(encbytes.ToArray());
        }
Esempio n. 3
0
        public void TestFileEncrypt()
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            var rsa = _loadRSA(Encrypting._PUBKEY);

            BackupLib.FileEncrypt enc = new BackupLib.FileEncrypt(rsa);
            //var srcfile = new FileStream("c:\\tmp\\foo.txt"/*"c:\\temp\\dumps\\ttirdreport.20170116_134248.xml"*/, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            //var srcfile = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(Encrypting._PUBKEY));
            var srcfile = new FileStream("/data2/photos/source/alpha7/2020/09-oregon/0930/DSC00773.ARW"
                                         , FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.ReadWrite);

            var encbytes = enc.encrypt(srcfile);

            /* persist the encrypted file. */
            var destpath = "c:\\tmp\\encfile.enc";

            if (System.Environment.OSVersion.Platform == PlatformID.Unix)
            {
                destpath = "/data2/temp/foo.net.tst";
            }
            var destfile = new FileStream(destpath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);

            encbytes.WriteTo(destfile);
            destfile.Flush();
            encbytes.Seek(0, SeekOrigin.Begin);

            destfile.Dispose();
            destfile = null;
            srcfile  = null;
            sw.Stop();
            TestContext.Progress.WriteLine("enc took {0:00}m {1:00}.{2:000}s", sw.Elapsed.Minutes, sw.Elapsed.Seconds, sw.Elapsed.Milliseconds);

            var b64 = Convert.ToBase64String(encbytes.ToArray());
        }