Author: ASilverblatt | Posted on: 8/10/2009 2:55:22 PM | Views : 400

I need to add triple DES encryption/decryption to a C# ASP.NET project under VS 2005.  I had already implemented it in an earlier VB.NET project (also under VS2005), so I attempted to just translate my working VB.NET code to C#, but I can't get it to work (both versions are shown below). The function Encrypt3DES appears to work correctly, but when I feed it's output back into Decrypt3DES it throws a "Bad Data." exception on the the line "CStream.FlushFinalBlock();".  If I remove that line, no exception is thrown but the output is gobbledygook, bearing no resemblance to the original clear text, and including some non-displayable character rendered as squares.  What am I doing wrong?
C# code:

using System;
using System.Data;
using System.Configuration;
using System.IO;
using System.Security.Cryptography;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using Sys ...

Go to the complete details ...