示例#1
0
        public string Upload(string path, string filename, string key, int alg)
        {
            try
            {
                byte[]     f  = File.ReadAllBytes(path);
                StoredFile sf = new StoredFile();
                sf.username = Username;
                sf.filename = filename;
                sf.hash     = MD5.HashString(f);
                switch (alg)
                {
                case 0:
                    sf.data = DoubleTransposition.Encrypt(f, key, sf.hash);
                    sf.size = sf.data.Length;
                    break;

                case 1:
                    sf.data = XTEA.Encrypt(f, key, sf.hash);
                    sf.size = sf.data.Length;
                    break;

                default: throw new Exception("You have not chosen an algorithm.");
                }

                svc.Upload(Username, sf, Token);
                Refresh();
                return("File successfuly uploaded.");
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
        private void ButtonEncrypt_Click(object sender, EventArgs e)
        {
            if (textBoxEncryptOriginal.TextLength == 0)
            {
                return;
            }
            var encrypt = chiper.Encrypt(textBoxEncryptOriginal.Text);

            textBoxEncrypt.Text = encrypt;
        }