473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Problem in 3DES decryption using CBC cipher mode

I am using CBC as the cipher mode to decrypt some text I'd encrypted
using the same mode for 3DES algorithm. My decrypt does not return the
correct result because the TransformBlock method returns 0 as bytes
read. Here's my code:

public static string Decrypt(string seed)
{
System.IO.MemoryStream stream = new System.IO.MemoryStream();

TripleDESCryptoServiceProvider TripleDESProvider = new
TripleDESCryptoServiceProvider();
TripleDESProvider.Key = new
System.Text.ASCIIEncoding().GetBytes(ComputeHash(N ativeEncryptionKey));
TripleDESProvider.Mode = CipherMode.CBC;
ICryptoTransform Decryptor = TripleDESProvider.CreateDecryptor();
byte[] bSeed = new System.Text.ASCIIEncoding().GetBytes(seed);

int numBlocks = (int)(bSeed.Length / TripleDESProvider.IV.Length);
int finalBlockSize = (int) (bSeed.Length %
TripleDESProvider.IV.Length);
int pos = 0;
byte[] btmp;

for (int i = 0; i < numBlocks; i++)
{
btmp = new byte[TripleDESProvider.IV.Length];
int bytesRead = Decryptor.TransformBlock(bSeed, i *
TripleDESProvider.IV.Length, TripleDESProvider.IV.Length, btmp, 0);
stream.Write(btmp, 0, btmp.Length);
pos += btmp.Length;
}

if (finalBlockSize 0)
{
btmp = null;
int bytesRead = numBlocks * TripleDESProvider.IV.Length;
btmp = Decryptor.TransformFinalBlock(bSeed, pos, finalBlockSize);
if (btmp.Length 0)
stream.Write(btmp, 0, btmp.Length);
}
Decryptor = null;
bSeed = null;
TripleDESProvider = null;

return new System.Text.ASCIIEncoding().GetString(stream.ToArr ay());
}
Anyone?

Aug 24 '06 #1
0 1965

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: novice | last post by:
Is there any method to decrypt a RSA-encrypted string given the private key only in Visual C++? I have tried the following avenues for a long time: - Microsoft Platform SDK CryptoAPI
5
by: sylvian stone | last post by:
Hi, I'm getting some strange errors that I cannot pin down: Warning: mcrypt_generic_init(): Iv size incorrect; supplied length: 7, needed: 8 in...... This is strange because the data is...
3
by: Michael Bebenita | last post by:
Hi, A Java application is encrypting a block of text using 3DES ECB mode and PKCS5 padding. I need to decrypt this text using C#. I've extracted the 192 bit key using the getEncoded() method of...
1
by: Saper\(ek\) | last post by:
I need to encrypt some data in my program, so I've created 2 functions to encrypt and decrypt data. I've created a simple program to test it, and... it crashes. It wors ok on XP, but on win98 it...
2
by: | last post by:
Greetings, I am trying to build an interface into an existing system which accepts UTF-8 encoded "messages". In these messages, there is a unencrypted base64 "key" in the header which is used to...
0
by: Phil C. | last post by:
(Cross post from framework.aspnet.security) Hi. I testing some asp.net code that generates a 256 bit Aes Symmetric Key and a 256 bit entropy value. I encrypt the Aes key(without storing it as...
8
by: den 2005 | last post by:
Hi everybody, I am not sure where to put this in this forum. So, I posted this at several topics. I created a class library that has two public methods Encrypt() and Decrypt(). I reference this...
2
by: Bernard Dhooghe | last post by:
The information center writes: "Encryption Algorithm: The internal encryption algorithm used is RC2 block cipher with padding, the 128-bit secret key is derived from the password using a MD2...
4
by: Ben | last post by:
Hi, i have already posted a more or less similar thread but it's gone unsolved with the flow of the other threads .. When an anonymous user has created an new account (with the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.