Results 1 to 4 of 4

Thread: 3DES Decryption

  1. #1
    Join Date
    Jun 2004
    Posts
    296
    Rep Power
    0

    Default 3DES Decryption

    I am having a little trouble decrypting in C#, I keep getting an exception 'CryptographicException' exception being thrown with a message of 'Bad Data', does any one know what this means, here is the code below. It works for things I encrypted, but im trying decrypt something that i got from a device. A random number challenge, that is what is giving me the exception.

    Code:
    public string DecryptMessage(string encryptedBase64, string password)
    		{
    			TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
    			des.IV = new byte[8];
    			PasswordDeriveBytes pdb = new PasswordDeriveBytes(password, new byte[0]);
    			des.Key = pdb.CryptDeriveKey("RC2", "MD5", 128, new byte[8]);
    			byte[] encryptedBytes = ToByteArray(encryptedBase64);
    			MemoryStream ms = new MemoryStream(encryptedBase64.Length * 2);
    			CryptoStream decStream = new CryptoStream(ms, des.CreateDecryptor(),
    				CryptoStreamMode.Write);
    			decStream.Write(encryptedBytes, 0, encryptedBytes.Length);
    			decStream.FlushFinalBlock();
    			byte[] plainBytes = new byte[ms.Length];
    			ms.Position = 0;
    			ms.Read(plainBytes, 0, (int)ms.Length);
    			decStream.Close();
    			return Encoding.UTF8.GetString(plainBytes);
    		}

  2. #2
    Join Date
    Jan 2005
    Posts
    3,151
    Rep Power
    0

    Default

    c#? meh
    Are those microsoft 3des functions?

    Use blowfish, its faster and more secure

  3. #3
    Join Date
    Jun 2004
    Posts
    296
    Rep Power
    0

    Default

    yup, microsoft 3des functions, the problem is the device that I am interfacing with uses 3DES. Actually I figured out the problem. I wasnt supposed to decode the random number, rather I was supposed to encrypt and send it back to the device for the device to decrypt and get back the original number. I wasnt thinking straight.

  4. #4
    Join Date
    Jan 2005
    Posts
    3,151
    Rep Power
    0

    Default

    hmm.. so that challenge goes:

    1. The device sends you a plaintext random data.

    2. You use your keys and 3des to encrypt that number and send it back to the device.

    3. The device uses its keys that should match your keys to decode that cyphertext to get verification?

    Please say no.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •