Quantcast
Channel: Rebex Q&A Forum - Recent questions and answers
Viewing all articles
Browse latest Browse all 3862

Answered: Decrypting a file that has been encrypted twice

$
0
0
Can you see why the following code is not working?

Encrypting:
var file = "test.txt.plain";
            var password = "123";

            var cryptor = new FileEncryption { EncryptionAlgorithm = FileEncryptionAlgorithm.AesCbc };
            cryptor.SetPassword(password);
            cryptor.OverwriteExistingFile = true;
            cryptor.Encrypt(file, $"{file}.die");

            var cryptor2 = new FileEncryption { EncryptionAlgorithm = FileEncryptionAlgorithm.TwofishCbc };
            cryptor2.SetPassword(password);
            cryptor2.Encrypt($"{file}.die", file+".die2");

And then decrypting:
var password = "123";
            var file = "test.txt.plain";

            var cryptor = new FileEncryption
            {
                EncryptionAlgorithm = FileEncryptionAlgorithm.TwofishCbc,
                OverwriteExistingFile = true
            };
            cryptor.SetPassword(password);
            cryptor.Decrypt(file, $"{file}.dec"); //<-- EXCEPTION

            cryptor.EncryptionAlgorithm = FileEncryptionAlgorithm.AesCbc;
            cryptor.SetPassword(password);
            cryptor.Decrypt($"{file}.dec", file);

Viewing all articles
Browse latest Browse all 3862

Trending Articles