Re: CryptoStream makes encrypted data bigger than original string
From: Burke ATILLA (burke_at_verisoft.com.tr)
Date: 02/06/04
- Next message: Mike: "Inherit from DataSet"
- Previous message: VM: "Re: streamwriter and streamreader and closing files"
- In reply to: Tim Smelser: "Re: CryptoStream makes encrypted data bigger than original string"
- Next in thread: Rob Teixeira [MVP]: "Re: CryptoStream makes encrypted data bigger than original string"
- Reply: Rob Teixeira [MVP]: "Re: CryptoStream makes encrypted data bigger than original string"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 6 Feb 2004 20:05:37 +0200
I use the code snippet below.
DESCryptoServiceProvider m_csp = new DESCryptoServiceProvider();
m_csp.Mode=CipherMode.ECB;
byte[] pIV = new byte[8];
int outref;
byte[] pData = new byte[8]{0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};;
byte[] pKey = new byte[8]{0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};;
//pData = Verisoft.General.Encoder.Pack(Data,out outref);
byte[] outData = new byte[8];
ICryptoTransform ict=null;
ict = m_csp.CreateEncryptor(pKey,pIV);
outData = ict.TransformFinalBlock(pData,0,8);
string hexString="";
for (int i=0; i<outData.Length; i++)
{
hexString += outData[i].ToString("X2");
}
Console.WriteLine("Enc - {0}", hexString);
ict=null;
ict = m_csp.CreateDecryptor(pKey,pIV);
outData = ict.TransformFinalBlock(outData,0,16);
hexString="";
for (int i=0; i<outData.Length; i++)
{
hexString += outData[i].ToString("X2");
}
Console.WriteLine("Dec - {0}", hexString);
As you see if you use Encrypton result "outData" for decryption it seems
everything going fine. but if you use first 8 bytes you will get an
exception as i mention before "bad data".
so i asked what is last 8 bytes??
"Tim Smelser" <t_smelser@snotmail.com> wrote in message
news:1j1m3g8sh70l6.1kya7wx2gz3j2$.dlg@40tude.net...
> On Fri, 6 Feb 2004 08:31:09 -0800, Burke Atilla wrote:
>
> > While encrypting data with DES through CryptoStream makes encrypted data
bigger than original string. if we have 8 byte key and 8 byte of data then
the mode is ECB. output encrypted data is 16 bytes long. first 8 bytes is
out encrypted key but last 8 byte unknown. and while decrypting if we
couldn't supply this 8 bytes we couldnt decrypt data. and get exception "Bad
Data".
> > What is this 8 bytes?
> > and how can i supply this data if i have only the encrypted 8 bytes.
>
> If all that you are encrypting/descrypting is an 8-byte block, rather
> than creating a CryptoStream why not just use the TransformFinalBlock
> method of the DESCryptoServiceProvider's ICryptoTransform? That way
> everything stays in nice 8-byte arrays.
>
> HTH,
> Tim
> --
> Tim Smelser - MVP Visual C#
> To email me, make the snot hot.
- Next message: Mike: "Inherit from DataSet"
- Previous message: VM: "Re: streamwriter and streamreader and closing files"
- In reply to: Tim Smelser: "Re: CryptoStream makes encrypted data bigger than original string"
- Next in thread: Rob Teixeira [MVP]: "Re: CryptoStream makes encrypted data bigger than original string"
- Reply: Rob Teixeira [MVP]: "Re: CryptoStream makes encrypted data bigger than original string"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|