473,785 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Example from VB NET 2005 PasswordDeriveB ytes Class

Hello,

In the Visual Basic example I see the next line:
tdes.Key = pdb.CryptDerive Key("TripleDES" , "SHA1", 192, tdes.IV)

tdes.Key is obviously created.
but what about tdes.IV?

This value is never filled if I'm correct?

help code:
Imports System
Imports System.Security .Cryptography
Imports System.Text

Module PasswordDerived BytesExample
Sub Main(ByVal args() As String)

' Get a password from the user.
Console.WriteLi ne("Enter a password to produce a key:")

'************** *************** *************** ************
'* Security Note: Never hard-code a password within your
'* source code. Hard-coded passwords can be retrieved
'* from a compiled assembly.
'************** *************** *************** ************
Dim pwd As Byte() = Encoding.Unicod e.GetBytes(Cons ole.ReadLine())

Dim salt As Byte() = createRandomSal t(7)

' Create a TripleDESCrypto ServiceProvider object.
Dim tdes As New TripleDESCrypto ServiceProvider ()

Try
Console.WriteLi ne("Creating a key with PasswordDeriveB ytes...")

' Create a PasswordDeriveB ytes object and then create
' a TripleDES key from the password and salt.
Dim pdb As New PasswordDeriveB ytes(pwd, salt)

' Create the key and add it to the Key property.
tdes.Key = pdb.CryptDerive Key("TripleDES" , "SHA1", 192, tdes.IV)

Console.WriteLi ne("Operation complete.")
Catch e As Exception
Console.WriteLi ne(e.Message)
Finally
' Clear the buffers
clearBytes(pwd)
clearBytes(salt )

' Clear the key.
tdes.Clear()
End Try

Console.ReadLin e()

End Sub
'************** *************** *************** ************
'* Helper methods:
'* createRandomSal t: Generates a random salt value of the
'* specified length.
'*
'* clearBytes: Clear the bytes in a buffer so they can't
'* later be read from memory.
'************** *************** *************** ************
Function createRandomSal t(ByVal Length As Integer) As Byte()
' Create a buffer
Dim randBytes() As Byte

If Length >= 1 Then
randBytes = New Byte(Length) {}
Else
randBytes = New Byte(0) {}
End If

' Create a new RNGCryptoServic eProvider.
Dim rand As New RNGCryptoServic eProvider()

' Fill the buffer with random bytes.
rand.GetBytes(r andBytes)

' return the bytes.
Return randBytes

End Function
Sub clearBytes(ByVa l Buffer() As Byte)
' Check arguments.
If Buffer Is Nothing Then
Throw New ArgumentExcepti on("Buffer")
End If

' Set each byte in the buffer to 0.
Dim x As Integer
For x = 0 To Buffer.Length - 1
Buffer(x) = 0
Next x

End Sub
End Module
Jun 27 '06 #1
0 1899

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

Similar topics

6
1796
by: Steve Jorgensen | last post by:
I'm posting this message for 2 reasons. First, I'm still pretty new and shakey to the whole Acceptance Testing thing, and I'm hoping for some feedback on whether I'm on the right track. Second, although all the Agile literature talks about the importance of doing Acceptance Testing, there's very little in any of the books or out on the Web that helps with how to do it. If I am on the right track, this will be one more helpful item...
5
512
by: Mike Owen | last post by:
Hi, I have just used the import Wizard to import a VS 2003 app to VS 2005. I have a lot of work to do to enable it to compile successfully with all the errors and warnings it gave me, but as a starting point the compiler can no longer find the function as at the bottom of this posting, that was in the Global.asax.vb file. All the function does is give an easy / quick way of getting the application
8
6459
by: Phil Lee | last post by:
I'm sure this is possible but I just can't see how to do it. I want to add schemas to my solution and have C# classes automatically generated from them. I can see how to generate typed DataSet's with the MSDataSetGenerator custom tool. Is there something similar for simple schemas? Regards Phil Lee
6
2327
by: cj | last post by:
Lets just take this example I'm looking at now. I'm looking at the help screen titled .NET Framework Class Library FolderBrowserDialog Class . It gives an example at the bottom that begins with: ' The following example displays an application that provides the ability to ' open rich text files (rtf) into the RichTextBox. The example demonstrates ' using the FolderBrowserDialog to set the default directory for opening files. ' The...
2
2141
by: Marco Wedekind | last post by:
Hello all, I've just read about typelists and their implementation in C++ using templates in http://www.ddj.com/dept/cpp/184403813. Now my very first test code using typelists does not compile... I just cannot compile the example explained in the article on Visual Studio 2005 or gcc 3.3.4 (to few template arguments). I would be glad, if some template-guru among you could take a look at the source code below and check, if I simply made...
5
14276
by: Gav | last post by:
I'm writing a windows application (using C# VS 2005 Pro) to access a MS SQL database and although it is working fine (up to now) I'm not sure I'm going about it in the best way. Can anybody point me to any good examples online that i can look at, found loads of web applications but struggling to find a good windows application example. thanks Gav
0
2065
by: Stephen Thomas | last post by:
Hi there I wonder if any one has encountered this problem or can suggest what is wrong. I am trying the a procedure from the msn site but get the following message: Error 1 The type or namespace name 'LiveSearch' does not exist in the namespace 'ConsoleSampleWebSearch' (are you missing an assembly reference?) C:\Documents and Settings\Compaq\Local Settings\Application Data\Temporary Projects\ConsoleSampleWebSearch\Program.cs 13 30...
23
2483
by: =?Utf-8?B?TWlrZTE5NDI=?= | last post by:
This is an example that is supposed to work in VB http://support.microsoft.com/kb/175512/en-us After spending a couple of hours downloading and installing VB Express 2008 after someone told me it was easy, the thing doesn't work any better. These two instruction lines are not functional 3. Place a Common Dialog control on the form. 4. From the Insert menu, select Module to add a single code module to the project. There is no Common...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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,...
0
10152
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 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...
1
10092
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
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 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...
0
8974
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
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
3
2880
bsmnconsultancy
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...

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.