473,796 Members | 2,512 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 1900

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
6460
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
2485
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
9673
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
10452
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10221
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
10169
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
10003
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...
1
7546
isladogs
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...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
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...
0
5569
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.