473,383 Members | 1,853 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,383 software developers and data experts.

Example from VB NET 2005 PasswordDeriveBytes Class

Hello,

In the Visual Basic example I see the next line:
tdes.Key = pdb.CryptDeriveKey("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 PasswordDerivedBytesExample
Sub Main(ByVal args() As String)

' Get a password from the user.
Console.WriteLine("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.Unicode.GetBytes(Console.ReadLine())

Dim salt As Byte() = createRandomSalt(7)

' Create a TripleDESCryptoServiceProvider object.
Dim tdes As New TripleDESCryptoServiceProvider()

Try
Console.WriteLine("Creating a key with PasswordDeriveBytes...")

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

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

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

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

Console.ReadLine()

End Sub
'************************************************* *******
'* Helper methods:
'* createRandomSalt: 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 createRandomSalt(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 RNGCryptoServiceProvider.
Dim rand As New RNGCryptoServiceProvider()

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

' return the bytes.
Return randBytes

End Function
Sub clearBytes(ByVal Buffer() As Byte)
' Check arguments.
If Buffer Is Nothing Then
Throw New ArgumentException("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 1873

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

Similar topics

6
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,...
5
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...
8
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...
6
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:...
2
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...
5
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...
0
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...
23
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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: 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...

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.