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. 4 4584
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 TransformFinalB lock
method of the DESCryptoServic eProvider's ICryptoTransfor m? That way
everything stays in nice 8-byte arrays.
HTH,
Tim
--
Tim Smelser - MVP Visual C#
To email me, make the snot hot.
I use the code snippet below.
DESCryptoServic eProvider m_csp = new DESCryptoServic eProvider();
m_csp.Mode=Ciph erMode.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.Genera l.Encoder.Pack( Data,out outref);
byte[] outData = new byte[8];
ICryptoTransfor m ict=null;
ict = m_csp.CreateEnc ryptor(pKey,pIV );
outData = ict.TransformFi nalBlock(pData, 0,8);
string hexString="";
for (int i=0; i<outData.Lengt h; i++)
{
hexString += outData[i].ToString("X2") ;
}
Console.WriteLi ne("Enc - {0}", hexString);
ict=null;
ict = m_csp.CreateDec ryptor(pKey,pIV );
outData = ict.TransformFi nalBlock(outDat a,0,16);
hexString="";
for (int i=0; i<outData.Lengt h; i++)
{
hexString += outData[i].ToString("X2") ;
}
Console.WriteLi ne("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_*******@snot mail.com> wrote in message
news:1j******** *************** *******@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 TransformFinalB lock method of the DESCryptoServic eProvider's ICryptoTransfor m? That way everything stays in nice 8-byte arrays.
HTH, Tim -- Tim Smelser - MVP Visual C# To email me, make the snot hot.
m_csp.Padding = PaddingMode.Non e
That will fix your problem, but realize that you are using relatively weak
encryption here. You're Initialization Vector is all zero, so it's quite
easy to attain just by sheer trial and error. You are using ECB mode, which
supplies no feedback to the cipher chain, which will create repeating
patterns of cipher text if there are repeating patterns in the plain text -
this can expose weaknesses that allow cryptanalysis to decode your key.
Finally, the DES algorithm isn't that strong. I suggest using TripleDES or
AES (with a 256-bit key if possible).
-Rob Teixeira [MVP]
"Burke ATILLA" <bu***@verisoft .com.tr> wrote in message
news:OY******** ******@TK2MSFTN GP12.phx.gbl... I use the code snippet below. DESCryptoServic eProvider m_csp = new DESCryptoServic eProvider(); m_csp.Mode=Ciph erMode.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.Genera l.Encoder.Pack( Data,out outref); byte[] outData = new byte[8]; ICryptoTransfor m ict=null; ict = m_csp.CreateEnc ryptor(pKey,pIV ); outData = ict.TransformFi nalBlock(pData, 0,8); string hexString=""; for (int i=0; i<outData.Lengt h; i++) { hexString += outData[i].ToString("X2") ; } Console.WriteLi ne("Enc - {0}", hexString); ict=null; ict = m_csp.CreateDec ryptor(pKey,pIV ); outData = ict.TransformFi nalBlock(outDat a,0,16); hexString=""; for (int i=0; i<outData.Lengt h; i++) { hexString += outData[i].ToString("X2") ; } Console.WriteLi ne("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_*******@snot mail.com> wrote in message news:1j******** *************** *******@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 TransformFinalB lock method of the DESCryptoServic eProvider's ICryptoTransfor m? That way everything stays in nice 8-byte arrays.
HTH, Tim -- Tim Smelser - MVP Visual C# To email me, make the snot hot.
Yes that it is. problem fixed. thanks for your comments below. but we are
developing Credit Card Management System and VISA and MASTERCARD uses ECB.
and no way out for this reason.
Thanks again.
Burke.
"Rob Teixeira [MVP]" <RobTeixeira@@m sn.com> wrote in message
news:OC******** ******@tk2msftn gp13.phx.gbl... m_csp.Padding = PaddingMode.Non e
That will fix your problem, but realize that you are using relatively weak encryption here. You're Initialization Vector is all zero, so it's quite easy to attain just by sheer trial and error. You are using ECB mode,
which supplies no feedback to the cipher chain, which will create repeating patterns of cipher text if there are repeating patterns in the plain
text - this can expose weaknesses that allow cryptanalysis to decode your key. Finally, the DES algorithm isn't that strong. I suggest using TripleDES or AES (with a 256-bit key if possible).
-Rob Teixeira [MVP]
"Burke ATILLA" <bu***@verisoft .com.tr> wrote in message news:OY******** ******@TK2MSFTN GP12.phx.gbl... I use the code snippet below. DESCryptoServic eProvider m_csp = new DESCryptoServic eProvider(); m_csp.Mode=Ciph erMode.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.Genera l.Encoder.Pack( Data,out outref); byte[] outData = new byte[8]; ICryptoTransfor m ict=null; ict = m_csp.CreateEnc ryptor(pKey,pIV ); outData = ict.TransformFi nalBlock(pData, 0,8); string hexString=""; for (int i=0; i<outData.Lengt h; i++) { hexString += outData[i].ToString("X2") ; } Console.WriteLi ne("Enc - {0}", hexString); ict=null; ict = m_csp.CreateDec ryptor(pKey,pIV ); outData = ict.TransformFi nalBlock(outDat a,0,16); hexString=""; for (int i=0; i<outData.Lengt h; i++) { hexString += outData[i].ToString("X2") ; } Console.WriteLi ne("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_*******@snot mail.com> wrote in message news:1j******** *************** *******@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 TransformFinalB lock method of the DESCryptoServic eProvider's ICryptoTransfor m? That way everything stays in nice 8-byte arrays.
HTH, Tim -- Tim Smelser - MVP Visual C# To email me, make the snot hot.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stingray |
last post by:
Are there any know problems with using a MemoryStream as a backing store for
a CryptoStream? I'm trying to simply encrypt and decrypt text in memory.
I'd like to create some simple methods to encrypt text before writing to a
database and decrypt it when reading it back. I figured I'd use a
MemoryStream that I can either store as a blob or convert to a string and
store as a varchar. Anyway, I can't get the CryptoStream to write to the...
|
by: MattP |
last post by:
Ok, with the help of some examples found on the web and some minor
modifications on our own, we have a simple and working encrypt and
decrypt solution. It runs as a service, watches for files with a
specific extension in a specific directory. The files are uploaded by
FTP to this directory. The service then does the following steps:
1) Verify it can open the file (so we know it's fully uploaded).
2) Try to decrypt the file with known...
|
by: weixiang |
last post by:
Hi,
I want to use DES and CryptoStream to serialize a encrypted stream to a file
with a header "CRYPT". And I wrote these code:
To store:
FileStream fileStream = new FileStream(fileName, FileMode.Create,
FileAccess.Write, FileShare.None);
byte signture = AE.GetBytes("CRYPT");
|
by: pseudonym |
last post by:
To keep this short, assume the function working_test() works perfectly
(because it does), while
failing_test() is not. My GetCodec function returns a Stream (CryptoStream)
object wrapped around the Stream it is passed.
private function working_test()
{
string f = "c:\\test.dat";
StreamWriter w;
StreamReader r;
|
by: Todd Gruben |
last post by:
I am trying to send some encrypted data from a php application to be
decoded in a .Net application. Both apps encode/decode a given string
but generate different encrypted results. Anyone have any idea? Code
to follow:
php====>
<?php
// Designate string to be encrypted
$string = "This is a test";
| |
by: James |
last post by:
Hi,
I am developing a ActiveX Control which will be used in a web page.
The control will encrypt some value then decrypt it when the web page opens
next time.
I tested the control in a windows application and it works fine and no error
jumps.
However, when I tried to use it in a web page, problems came.
There is no problem for encrypting but the decrypting can't be finished.
The error jumped from the line below
|
by: pesso |
last post by:
I have the following code that's taken and modified from a got_dot_net
example.
I'm trying to decrypt an Xml file that's been encrypted. I can dump the
decrypted stream to the console, but if I try to load that into
XmlTextReader, it throws XmlException. I'd appreciate your help.
//create file stream to read encrypted file back
FileStream fsread = new FileStream(args, FileMode.Open,
FileAccess.Read);
|
by: Nicholas Holder |
last post by:
A client creates a connection to the server using the TCPListener/Client
classes and transfers data via a NetworkStream. When the client connects,
the server creates a process and redirects its StandardOut to traverse back
over the network to the client. I want to encrypt this data and the code I
have is below. However, occasionally during processing, I receive an
exception stating the PKCS7 padding is invalid and cannot be removed. I have...
|
by: Michael Sperlle |
last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems
to need changes to the kernel before it can be installed, and I have no
intention of going through whatever hell that would cause.
If I could create a large file that could be encrypted, and maybe add
files to it by appending them and putting in some kind of delimiter
between files, maybe a homemade version of truecrypt could be constructed.
Any idea what it...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |