Beispiel #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);
            }
        }
Beispiel #2
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);
        }