473,386 Members | 2,114 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,386 software developers and data experts.

DESCryptoServiceProvider - encryption question

Tom
Hi experts,

I have the following code, which works fine:

######################### C# snippet
########################################
string k = "12345678";
string input = "ABCDEFGH";

DES des_dec = new DESCryptoServiceProvider();
byte [] inbuff = ASCIIEncoding.ASCII.GetBytes(input);
byte [] bytesKey = Encoding.ASCII.GetBytes(k);
des_dec.Mode = CipherMode.ECB;
des_dec.Key = bytesKey;

MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des_dec.CreateEncryptor(),
CryptoStreamMode.Write);
cs.Write(inbuff, 0, inbuff.Length);
cs.Close();
byte [] encryptedData = ms.ToArray();
######################### end C# snippet
####################################

After executing the snippet, the byte array encryptedData contains 16
Bytes - although I just gave 8 bytes with inbuff. WHY ????

I am working on a class to communicate with an external device, which
en- and decrypts data using DES ECB standard (the simplest one).

The problem is: Encrypting by the same key and standards like showed
in the code snippet just generates an 8 byte encrypted array. This
result (generated by firmware of device which is programmed in ANSI-C)
can not be decrypted using the DESCryptoServiceProvider, it always
returns an exception with the meassage "Invalid Data".

Is there anything I did wrong ? Why does DESCryptoServiceProvider
generate a 16 byte array out of a 8 byte array input ??

Please help.

Thanks to all - greets from germany

Tom
Nov 16 '05 #1
2 5927
Hello Tom,

The extra 8 bytes are basically padding. Use the line,

des_dec.Padding = PaddingMode.None

to fix the problem, though realise that this is very insecure.

HTH,
Gary Short
Nov 16 '05 #2
Tom
Gary,

this solved my problem - thank you very much for your help !!

Regards

Thomas

ga**@computa.co.uk (Gary Short) wrote in message news:<17*************************@posting.google.c om>...
Hello Tom,

The extra 8 bytes are basically padding. Use the line,

des_dec.Padding = PaddingMode.None

to fix the problem, though realise that this is very insecure.

HTH,
Gary Short

Nov 16 '05 #3

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

Similar topics

14
by: Ray Cassick \(Home\) | last post by:
Ok, time to ask the question here.. I have been battling over this one for sometime now and just have to ask it. I have created a few classes that I use to act a security keys. These classes get...
1
by: Ondrej Sevecek | last post by:
Hello, would you please provide me with some simple sample of how to use the DESCryptoServiceProvider to encrypt a buffer byte buffer; with key byte key;
2
by: Salman | last post by:
When I run the below method with a 64 character string as input such as: sr.Encrypt("1234567890123456789012345678901234567890123456789012345678904444"); I get square boxes as my output, which...
113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
3
by: wolf | last post by:
Can I de-crypt the data by java which is crypt by DESCryptoServiceProvider? The following is my code to crypt data: string text = "This is My source data"; byte source =...
5
by: Joe | last post by:
I'm trying to figure out how to remove the characters padded to the end of my string without setting the Padding = PaddingMode.None. My original string passed in is 'passwordTest' and the...
1
by: =?Utf-8?B?bWljcm9ob2Y=?= | last post by:
Short version: Is there a way to configure (preferably programmatically) the max encryption strength that will be used by the framework when connecting to a particular SSL-protected web service? ...
25
by: eggie5 | last post by:
I have a form where a user can change his password, but I'm confused on how to prevent this from being transmitted in plain text. Well, I know how not to transmit it in plain text - use any type...
19
by: klenwell | last post by:
Another request for comments here. I'd like to accomplish something like the scheme outlined at this page here: http://tinyurl.com/3dtcdr In a nutshell, the form uses javascript to hash...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.