Exemplo n.º 1
0
        private void add()
        {
            Product pro = new Product();

            Console.WriteLine("********* ADD ********");

            /*Console.Write("Enter Product ID: ");
             * pro.ProductID = Int16.Parse(Console.ReadLine());
             * string newURI = uri + "get-product/" + pro.ProductID.ToString();
             * if (client.GetAsync(newURI).Result.StatusCode == System.Net.HttpStatusCode.OK) {
             *  Console.WriteLine("ID existed!!!");
             *
             *  return;
             * }*/

            Console.Write("Enter Product Name: ");
            pro.ProductName = Console.ReadLine();

            Console.Write("Enter Product Price: ");
            pro.UnitPrice = Int16.Parse(Console.ReadLine());

            Console.Write("Enter Product Quantity: ");
            pro.Quantity = Int16.Parse(Console.ReadLine());

            #region get-public-key
            string newURI = baseURI + "get-public-key";
            //HttpResponseMessage response = await client.GetAsync(newURI);
            var response = client.GetStringAsync(newURI).Result.ToString();
            Obj obj      = JsonConvert.DeserializeObject <Obj>(response);
            PgpEncryptionKeys encryptionKeys = new PgpEncryptionKeys(obj.file);
            #endregion

            #region add API
            newURI = uri + "create-product/";

            PgpEncrypt encrypter = new PgpEncrypt(encryptionKeys);
            string     s         = JsonConvert.SerializeObject(pro);

            System.IO.MemoryStream output = new System.IO.MemoryStream();
            encrypter.EncryptAndSign(output, s);
            output.Close();

            KeyObj newObj = new KeyObj();
            newObj.kByte = output.ToArray();

            HttpResponseMessage resp = client.PostAsJsonAsync(newURI, newObj).Result;
            #endregion

            if (resp.StatusCode == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine("Add successful!!!");
            }
            else
            {
                Console.WriteLine("Add fail!!!");
            }
        }
Exemplo n.º 2
0
        public void EncryptAndSignTest()
        {
            PgpEncryptionKeys encryptionKeys      = null;                           // TODO: Initialize to an appropriate value
            PgpEncrypt        target              = new PgpEncrypt(encryptionKeys); // TODO: Initialize to an appropriate value
            Stream            outputStream        = null;                           // TODO: Initialize to an appropriate value
            FileInfo          unencryptedFileInfo = null;                           // TODO: Initialize to an appropriate value

            target.EncryptAndSign(outputStream, unencryptedFileInfo);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles the actions for the current working file for encryption and transmission
        /// </summary>
        /// <param name="workingFile"></param>
        private void HandleMovedVendorFile(VendorLite vl, int _count)
        {
            var source             = vl.filePath;
            var file               = Path.GetFileName(source);
            var dest               = String.Format(@"{0}\{1}", Server.MapPath(vl.workingPath), file);
            var PublicKeyFileName  = Server.MapPath(vl.publicKeyPath);
            var PrivateKeyFileName = Server.MapPath(appvars.SignPrivateKey);
            var vt             = (VendorType)Enum.Parse(typeof(VendorType), vl.VendorName, true);
            var EncryptionFile = String.Format("{0}{1}", dest.Replace(Path.GetFileName(dest), ""), appvars.ReturnNewFileName(vt));

            //Get the user info from their session var...
            SetUserInformation();
            vl.UserID = this.CurrentUser.UserObject.LoginID.ToLower();

            if (!File.Exists(dest))
            {
                FileStream fs = File.Create(dest);
                fs.Close();
            }

            File.Copy(source, dest, true);

            PgpEncryptionKeys encryptionKeys = new PgpEncryptionKeys(PublicKeyFileName, PrivateKeyFileName, appvars.SignPassWord);
            PgpEncrypt        encrypter      = new PgpEncrypt(encryptionKeys);

            using (Stream outputStream = File.Create(EncryptionFile))
            {
                //build out the encypted file...
                encrypter.EncryptAndSign(outputStream, new FileInfo(dest));

                //Our file transfer class requires a fully qualified clean-up set...
                CleanUpFiles cuf = new CleanUpFiles();
                cuf.EncryptedFilePath  = EncryptionFile;
                cuf.TxtWorkingFilePath = dest;
                // we'll put in the script path later.... cuf.ClientScriptFilePath = "";
                //set the vL item's cleanupItems for the next routine..
                vl.cleanUpItems = cuf;
            }        //end using statement

            //construct the object and run it...
            FileTransfer fT = new FileTransfer(vl);

            fT.RunUpload();

            //File the report and store the files before clean-up...
            FileReport fr = new FileReport(vl);

            fr.SubmitReport();



            //clean up...
            FileCleanUp.CleanUpFileTransfer(vl.cleanUpItems);
        }    //handle the HandleMovedVendorFile
Exemplo n.º 4
0
        public void Encryption()
        {
            PgpEncryptionKeys encryptionKeys = new PgpEncryptionKeys(_keyRingHome + "\\" + publicKeyRingFilename, publicKeyEncryptionUserId, _keyRingHome + "\\" + secretKeyRingFilename, signatureKeyUserId, secretKeyRingPassphrase);

            PgpEncrypt encrypter = new PgpEncrypt(encryptionKeys, symmetricAlgorithm, compressionAlgorithm, sigHashAlgorithm);

            using (Stream outputStream = File.Create(filePath + "\\" + encryptedFile))
            {
                encrypter.EncryptAndSign(outputStream, new FileInfo(filePath + "\\" + originalInputFile), withArmor, withIntegrityCheck);
            }
            Console.WriteLine("Encryption Done !");
        }
Exemplo n.º 5
0
        public async void Encryption()
        {
            #region PGP Encryption

            PgpEncryptionKeys encryptionKeys = new PgpEncryptionKeys(@"D:\Keys\PGPPublicKey.asc");
            PgpEncrypt        encrypter      = new PgpEncrypt(encryptionKeys);
            using (Stream outputStream = File.Create("D:\\Keys\\EncryptData.txt"))
            {
                encrypter.EncryptAndSign(outputStream, new FileInfo(@"D:\Keys\PlainText.txt"));
            }
            Console.WriteLine("Encryption Done !");

            #endregion
        }
Exemplo n.º 6
0
        /// <summary>
        /// The encryption.
        /// </summary>
        private void Encryption()
        {
            #region PGP Encryption

            var encryptionKeys = new PgpEncryptionKeys(@"D:\Keys\PGPPublicKey.asc", @"D:\Keys\PGPPrivateKey.asc", "P@ll@m@lli");
            var encrypter      = new PgpEncrypt(encryptionKeys);
            using (Stream outputStream = File.Create(@"D:\Keys\EncryptData.txt"))
            {
                encrypter.EncryptAndSign(outputStream, new FileInfo(@"D:\Keys\PlainText.txt"));
            }

            this.InfoListBox.Items.Add("Encryption Done !");

            #endregion
        }
Exemplo n.º 7
0
        public byte[] Encrypt(byte[] data)
        {
            string tempDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Temp");

            if (!Directory.Exists(tempDir))
            {
                Directory.CreateDirectory(tempDir);
            }

            string fileName = Path.Combine(tempDir, Guid.NewGuid().ToString() + ".txt");

            using (var stream = File.Create(fileName))
            {
                stream.Write(data, 0, data.Length);
                stream.Flush();
            }

            try
            {
                using (MemoryStream outputStream = new MemoryStream())
                {
                    PgpEncryptionKeys encryptionKeys = new PgpEncryptionKeys(
                        GetPathToEncryptFile(),
                        GetPathToDecryptFile(),
                        _passPhrase);
                    PgpEncrypt encrypter = new PgpEncrypt(encryptionKeys);

                    encrypter.EncryptAndSign(outputStream, new FileInfo(fileName));

                    return(outputStream.ToArray());
                }
            }
            finally
            {
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
            }
        }
        private static async Task <bool> EncryptExcelContentAndSendToSFTP(FileStream fs, FileInfo file)
        {
            try
            {
                var clientKey     = GetConfigValue("SFPublicKey");
                var pfsPrivateKey = GetConfigValue("PFSPrivateKey");
                var password      = GetConfigValue("PGPPassword");

                //encrypt the generated file
                var objPgpEncryptionKeys = new PgpEncryptionKeys(clientKey, pfsPrivateKey, password);
                var objPgpEncrypt        = new PgpEncrypt(objPgpEncryptionKeys);

                objPgpEncrypt.EncryptAndSign(fs, file);

                //UploadExcelToSFTP(sftpHost, sftpUsername, sftpPassword, file.FullName, sftpDestination, sftpPort);

                return(true);
            }
            catch (Exception ex)
            {
                throw new PlatformCustomException(ex.Message);
            }
        }
Exemplo n.º 9
0
        private void update()
        {
            Product pro = new Product();

            Console.WriteLine("********** UPDATE *********");
            Console.Write("Enter Product ID: ");
            pro.ProductID = Int16.Parse(Console.ReadLine());
            string newURI = uri + "get-product/" + pro.ProductID.ToString();

            //Console.WriteLine(newURI);
            if (client.GetAsync(newURI).Result.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                Console.WriteLine("ID not found!!");
                return;
            }


            Console.Write("Enter New Product Name: ");
            pro.ProductName = Console.ReadLine();
            Console.Write("Enter New Product Price: ");
            pro.UnitPrice = Int16.Parse(Console.ReadLine());
            Console.Write("Enter New Product Quantity: ");
            pro.Quantity = Int16.Parse(Console.ReadLine());


            #region get-public-key
            newURI = baseURI + "get-public-key";
            //HttpResponseMessage response = await client.GetAsync(newURI);
            var response = client.GetStringAsync(newURI).Result.ToString();
            Obj obj      = JsonConvert.DeserializeObject <Obj>(response);
            PgpEncryptionKeys encryptionKeys = new PgpEncryptionKeys(obj.file);
            #endregion

            #region update API
            newURI = uri + "update-product/" + pro.ProductID.ToString();

            PgpEncrypt encrypter = new PgpEncrypt(encryptionKeys);
            string     s         = JsonConvert.SerializeObject(pro);

            System.IO.MemoryStream output = new System.IO.MemoryStream();
            encrypter.EncryptAndSign(output, s);
            output.Close();

            //MemoryStream ms = new MemoryStream();
            //PGPHandler.GetInstance().EncryptAndSign(Encoding.UTF8.GetBytes(request), ms);
            //String encryptedData = Encoding.UTF8.GetString(ms.ToArray());

            KeyObj newObj = new KeyObj();
            newObj.kByte = output.ToArray();

            HttpResponseMessage resp = client.PutAsJsonAsync(newURI, newObj).Result;
            #endregion


            if (resp.StatusCode == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine("Update successful!!!");
            }
            else
            {
                Console.WriteLine("Update fail!!!");
            }
        }