473,399 Members | 3,656 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,399 software developers and data experts.

DES.CreateEncryptor() Question

Hi ,

can some one explain me what does it mean those 2 params that i need

to pass the des.CreateEncryptor(rgbKey as byte,rgbIV as byte)
Best Regards ,

Tiraman :-)
Nov 20 '05 #1
4 7297
In modern cryptography, ciphers (crypto algorithms) are publicly available.
You can look at the alogorithm's math and know exactly what it's doing.
However, the math requires a secret key. With DES (and all "symmetric block
ciphers"), the key is used as part of the math to encrypt the data. The very
same key must be used to decrypt it. As you can see, the key is just a
sequence of bytes (it's actually a byte array, not just a single byte).

In .NET, when you create the initial symmetric block cipher object (in this
case, the DES object), it will automatically generate a
cryptographically-strong, random key sequence for you. When you call
CreateEncryptor, if you pass no key, the key in the base DES object is used.
However, as you can see with the method you wrote here, you can pass your
own key (because remember, you must use the same key to decrypt data that
you used to encrypt it in the first place).

As for the IV, it's used in various Feedback modes. If you encrypt straight
plain text one block at a time, and that data had repeating blocks, you
could end up with repeating encrypted blocks, and that could give away clues
to a malicious person looking to crack your encryption. Feedback takes bits
from the previous block and mathematically infuses that data with the next
block as it encrypts. That way, you get even more protection and more
unpreditcable results. However, the first block of data has nothing in front
of it to use as feedback, so the IV acts as a "fake" block of data used to
perform the feedback math on the first block. If you use a feedback mode
(.NET uses some form of feedback by default unless you turn it off), you
must also keep the IV byte sequence used to encrypt the data because you
can't decrypt the data without it. Make sure you keep both the Key and IV
private and safe at all times.

-Rob Teixeira [MVP]

"Tiraman" <ti*****@netvision.net.il> wrote in message
news:OX**************@TK2MSFTNGP12.phx.gbl...
Hi ,

can some one explain me what does it mean those 2 params that i need

to pass the des.CreateEncryptor(rgbKey as byte,rgbIV as byte)
Best Regards ,

Tiraman :-)

Nov 20 '05 #2
hi ,

first i would like to 10x for the gr8 explanation but it is still not so
clear to me .

i tried to use those 2 keys as follow
Dim rgbKey() As Byte = New UnicodeEncoding().GetBytes("abcd")

Dim rgbIV() As Byte = New UnicodeEncoding().GetBytes("SomeString")

Dim DesEnc As ICryptoTransform = Des.CreateEncryptor(rgbKey, rgbIV)

and i got the encryption and decryption as well but if i tried to put some
more text in the secret key it was failed bcz of

Specified key is not a valid size for this algorithm.

so how can i use those methods but for the above example ?

how can i change the size of the key ?

10x again

"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
news:OS*************@tk2msftngp13.phx.gbl...
In modern cryptography, ciphers (crypto algorithms) are publicly available. You can look at the alogorithm's math and know exactly what it's doing.
However, the math requires a secret key. With DES (and all "symmetric block ciphers"), the key is used as part of the math to encrypt the data. The very same key must be used to decrypt it. As you can see, the key is just a
sequence of bytes (it's actually a byte array, not just a single byte).

In .NET, when you create the initial symmetric block cipher object (in this case, the DES object), it will automatically generate a
cryptographically-strong, random key sequence for you. When you call
CreateEncryptor, if you pass no key, the key in the base DES object is used. However, as you can see with the method you wrote here, you can pass your
own key (because remember, you must use the same key to decrypt data that
you used to encrypt it in the first place).

As for the IV, it's used in various Feedback modes. If you encrypt straight plain text one block at a time, and that data had repeating blocks, you
could end up with repeating encrypted blocks, and that could give away clues to a malicious person looking to crack your encryption. Feedback takes bits from the previous block and mathematically infuses that data with the next
block as it encrypts. That way, you get even more protection and more
unpreditcable results. However, the first block of data has nothing in front of it to use as feedback, so the IV acts as a "fake" block of data used to
perform the feedback math on the first block. If you use a feedback mode
(.NET uses some form of feedback by default unless you turn it off), you
must also keep the IV byte sequence used to encrypt the data because you
can't decrypt the data without it. Make sure you keep both the Key and IV
private and safe at all times.

-Rob Teixeira [MVP]

"Tiraman" <ti*****@netvision.net.il> wrote in message
news:OX**************@TK2MSFTNGP12.phx.gbl...
Hi ,

can some one explain me what does it mean those 2 params that i need

to pass the des.CreateEncryptor(rgbKey as byte,rgbIV as byte)
Best Regards ,

Tiraman :-)


Nov 20 '05 #3
Ideally, the keys and IV should be generated randomly. Using the unicode
bytes may not be a good idea becuse it creates repeating sets of zeros in
your key data (in fact, half your key will be zeros for most string
characters used), and that may present vulnerabilities in the expanded key
and even encrypted data itself (clues that would give a potential hacker
insight into what the original key was).

But getting back to the data itself - the IV must always be exactly one
block in size. One block could be different number of bits depending on the
algorithm you use. For most block encryption algorithms, a block is 16 bits
or 32 bits. You can check the BlockSize property on the base algorithm
object.
The key length itself also depends on the algorithm. Most algorithms have at
least a few possible key lengths, which are typically multiples or factors
of the block size (or some relation thereof). You can check the KeySizes
property of the base cipher object for valid sizes of the algorithm you
choose.

On the other hand, if you want to create keys from password strings, rather
than use the strings directly, check out the PasswordDerrivedBytes class. If
you use that class, you can use variably sized input strings. But like I
said, your best bet would be to randomly generate the keys using something
like the RandomNumberGenerator class (both these classes are also in the
system.security.cryptography namespace).

-Rob Teixeira [MVP]
"Tiraman" <ti*****@netvision.net.il> wrote in message
news:eC**************@TK2MSFTNGP10.phx.gbl...
hi ,

first i would like to 10x for the gr8 explanation but it is still not so
clear to me .

i tried to use those 2 keys as follow
Dim rgbKey() As Byte = New UnicodeEncoding().GetBytes("abcd")

Dim rgbIV() As Byte = New UnicodeEncoding().GetBytes("SomeString")

Dim DesEnc As ICryptoTransform = Des.CreateEncryptor(rgbKey, rgbIV)

and i got the encryption and decryption as well but if i tried to put some
more text in the secret key it was failed bcz of

Specified key is not a valid size for this algorithm.

so how can i use those methods but for the above example ?

how can i change the size of the key ?

10x again

Nov 20 '05 #4
Hello Rob

10x for the explanation !

"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
news:ei**************@tk2msftngp13.phx.gbl...
Ideally, the keys and IV should be generated randomly. Using the unicode
bytes may not be a good idea becuse it creates repeating sets of zeros in
your key data (in fact, half your key will be zeros for most string
characters used), and that may present vulnerabilities in the expanded key
and even encrypted data itself (clues that would give a potential hacker
insight into what the original key was).

But getting back to the data itself - the IV must always be exactly one
block in size. One block could be different number of bits depending on the algorithm you use. For most block encryption algorithms, a block is 16 bits or 32 bits. You can check the BlockSize property on the base algorithm
object.
The key length itself also depends on the algorithm. Most algorithms have at least a few possible key lengths, which are typically multiples or factors
of the block size (or some relation thereof). You can check the KeySizes
property of the base cipher object for valid sizes of the algorithm you
choose.

On the other hand, if you want to create keys from password strings, rather than use the strings directly, check out the PasswordDerrivedBytes class. If you use that class, you can use variably sized input strings. But like I
said, your best bet would be to randomly generate the keys using something
like the RandomNumberGenerator class (both these classes are also in the
system.security.cryptography namespace).

-Rob Teixeira [MVP]
"Tiraman" <ti*****@netvision.net.il> wrote in message
news:eC**************@TK2MSFTNGP10.phx.gbl...
hi ,

first i would like to 10x for the gr8 explanation but it is still not so
clear to me .

i tried to use those 2 keys as follow
Dim rgbKey() As Byte = New UnicodeEncoding().GetBytes("abcd")

Dim rgbIV() As Byte = New UnicodeEncoding().GetBytes("SomeString")

Dim DesEnc As ICryptoTransform = Des.CreateEncryptor(rgbKey, rgbIV)

and i got the encryption and decryption as well but if i tried to put some more text in the secret key it was failed bcz of

Specified key is not a valid size for this algorithm.

so how can i use those methods but for the above example ?

how can i change the size of the key ?

10x again


Nov 20 '05 #5

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

Similar topics

3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
10
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
56
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
2
by: Allan Ebdrup | last post by:
Hi, I'm trying to render a Matrix question in my ASP.Net 2.0 page, A matrix question is a question where you have several options that can all be rated according to several possible ratings (from...
3
by: Zhang Weiwu | last post by:
Hello! I wrote this: ..required-question p:after { content: "*"; } Corresponding HTML: <div class="required-question"><p>Question Text</p><input /></div> <div...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...

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.