示例#1
0
        private void button2_Click(object sender, EventArgs e)
        {
            //ofd7Zip.Filter = "7Z files (*.7Z)|*.7z|All files (*.*)|*.*";

            this.ofd7Zip.Multiselect = false;
            if (!Directory.Exists(_CopyPathAES))
            {
                Directory.CreateDirectory(_CopyPathAES);
            }
            if (ofd7Zip.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = ofd7Zip.FileName;
                File.Copy(ofd7Zip.FileName, _CopyPathAES + @"\\" + ofd7Zip.SafeFileName, true);
                //SevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();
                //decoder.
                MyAES  myAES    = new MyAES();
                string password = "******";

                // Create sha256 hash
                //PKCS5_PBKDF2_HMAC_SHA1
                //HMACSHA1 hMACSHA1 = new HMACSHA1();
                SHA256 mySHA256 = SHA256Managed.Create();
                key = mySHA256.ComputeHash(Encoding.ASCII.GetBytes(password));

                // Create secret IV
                byte[] iv = new byte[16] {
                    0xd3, 0x31, 0x29, 0x4a, 0xae, 0x3d, 0xe5, 0xc5, 0xdf, 0x64, 0xd0, 0xf2, 0xa4, 0x97, 0xa2, 0x15
                };

                //string encrypted = myAES.EncryptString(message, key, iv);
                encrypted = myAES.FileToByteArray(_CopyPathAES + @"\\" + ofd7Zip.SafeFileName);
                string decrypted = myAES.DecryptString(encrypted, key, iv);
            }
        }
示例#2
0
        private void button3_Click(object sender, EventArgs e)
        {
            MyAES  myAES     = new MyAES();
            string roundtrip = myAES.DecryptStringFromBytes_Aes(encrypted, key);

            txtDecrypt.Text = roundtrip;
        }
示例#3
0
 private void button4_Click(object sender, EventArgs e)
 {
     using (var random = new RNGCryptoServiceProvider())
     {
         key = new byte[16];
         random.GetBytes(key);
         MyAES myAES = new MyAES();
         encrypted       = myAES.EncryptStringToBytes_Aes(txtinput.Text, key);
         txtEncrypt.Text = Convert.ToBase64String(encrypted);
     }
 }
示例#4
0
 private void button1_Click(object sender, EventArgs e)
 {
     using (var random = new RNGCryptoServiceProvider())
     {
         MyAES myAES = new MyAES();
         encrypted = myAES.FileToByteArray(_CopyPathAES + @"\\" + ofd7Zip.SafeFileName);
         key       = new byte[16];
         random.GetBytes(key);
         txtDecrypt.Text = myAES.DecryptStringFromBytes_Aes(encrypted, key);
         //myAES.DecryptFile(_CopyPathAES + @"\\" + ofd7Zip.SafeFileName, _CopyPathAES + @"\\ABCD");
     }
 }
示例#5
0
        private void button5_Click(object sender, EventArgs e)
        {
            MyAES  myAES    = new MyAES();
            string password = "******";

            // Create sha256 hash
            //PKCS5_PBKDF2_HMAC_SHA1
            //HMACSHA1 hMACSHA1 = new HMACSHA1();
            SHA256 mySHA256 = SHA256Managed.Create();

            key = mySHA256.ComputeHash(Encoding.ASCII.GetBytes(password));

            // Create secret IV
            byte[] iv = new byte[16] {
                0xd3, 0x31, 0x29, 0x4a, 0xae, 0x3d, 0xe5, 0xc5, 0xdf, 0x64, 0xd0, 0xf2, 0xa4, 0x97, 0xa2, 0x15
            };

            //string encrypted = myAES.EncryptString(message, key, iv);
            encrypted = myAES.FileToByteArray(_CopyPathAESencrypt + @"\\" + ofd7Zip.SafeFileName);
            string decrypted = myAES.DecryptString(encrypted, key, iv);
        }