SIGN UP
MEMBER LOGIN:
TECHNOLOGIES
Active Directory in VB.NET
ADO.NET in VB.NET
Algorithms and VB.NET
ASP.NET AJAX in VB.NET
ASP.NET using VB.NET
Assemblies in VB.NET
COM Interop in VB.NET
Cryptography in VB.NET
Crystal Reports in VB.NET
Database & DBA
Deployment in VB.NET
Design & Architecture
DirectX with VB.NET
Enterprise Development
Games in VB.NET
GDI+ in VB.NET
General
LINQ with VB.NET
Mobile Dev in VB.NET
Multithreading in VB.NET
Networking with VB.NET
Office and VB.NET
Printing in VB.NET
Remoting in VB.NET
Reports in VB.NET
Security in VB.NET
Silverlight using VB.NET
Speech in VB.NET
Strings, Arrays in VB.NET
Tablet PC
Tablet PC with VB.NET
VB.NET Articles
VB.NET Exception Handling
VB.NET FAQ
VB.NET How do I
VB.NET Language
VB.NET Tutorials
VB.NET Windows Service
VBA
Visual Basic 11
Visual Basic 2010
Visual Basic Language
WCF with VB.NET
Web Controls in VB.NET
Web Dev in VB.NET
Web Forms with VB.NET
Web Service in VB.NET
Windows Controls
Windows Forms VB.NET
Workflow in VB.NET
WPF using VB.NET
XAML in VB.NET
XML in VB.NET
FORUMS
BLOGS
Use of Excel.AddUnique Method in MS Excel to D ...
Use of PPT.ApplyTheme.BackgroundStyle in MS P ...
Use of PPT.InteractWithChartLocation in MS Pow ...
Simple Web Report With Pivot Table and Linq to ...
Print A Chart into a Byte Stream
Using New Audio Player Class With VB.NET
Display Top Ten Percent Item and bottom Ten pe ...
Use of PPT.ConvertTextToSmartArt in MS PowerP ...
How to Find Backup Folder Data Location Using ...
Calendar Control In WPF
ARTICLE
System.Security.Cryptography Namespace in VB.NET
Posted by
Dinesh Beniwal
in
Articles
|
Visual Basic Language
on
September 13, 2010
Tags:
Namespace
,
NETSystem.Security.Cryptography Namespace in VB.NET
,
System.Security.Cryptography
In this article I will explain you about System.Security.Cryptography Namespace in VB.NET.
Tweet
2037
0
0
Reader Level:
The System.Security.Cryptography namespace contains support for the most common symmetric (DES, 3DES, RC2, Rijndael), asymmetric (RSA, DSA), and hash (MD5, SHA-1, SHA-256, SHA- 384, SHA-512) cryptography algorithms. It also includes a helpful class to encrypt and decrypt streams. You can use this class, called CryptoStream, in combination with other stream classes or you can use several CryptoStream class objects together. With a little effort, you can feed the output of one CryptoStream object into another CryptoStream object.
Table 22.6 lists the classes and interfaces that are part of the System.Security.Cryptography namespace of the VB.NET Framework base class library. These classes and interfaces define the abstract object model for encryption algorithms within the VB.NET Framework. New algorithms may be added to the VB.NET Framework by subclassing and/or implementing a portion of these classes and interfaces.
Table 22.6: Classes and Interfaces in the System.Security.Cryptography Namespace
Listing 22.35 illustrates the use of DES and CryptoStream classes to encipher and decipher a file.
Listing 22.35: Cryptostream1.VB, CryptoStream with DES
Imports
System.IO
Imports
System.Security
Imports
System.Security.Cryptography
Imports
System.Text
Class
CryptoDESSample
Shared
Sub
Main(
ByVal
args
As
String
())
Dim
fsInput
As
New
FileStream(
"
c:\myfile.txt"
, FileMode.Open, FileAccess.Read
)
Dim
fsCiphered
As
New
FileStream(
"c:\ciphered.txt"
, FileMode.Create, FileAccess.Write
Dim
ourDESProvider
As
New
DESCryptoServiceProvider()
' our 8 byte DES secret key is 12345678
ourDESProvider.Key = ASCIIEncoding.ASCII.GetBytes(
"12345678"
)
ourDESProvider.IV = ASCIIEncoding.ASCII.GetBytes(
"12345678"
)
Dim
des1
As
ICryptoTransform = ourDESProvider.CreateEncryptor()
Dim
des2
As
ICryptoTransform = ourDESProvider.CreateDecryptor()
Dim
cryptostream1
As
New
CryptoStream(fsCiphered, des1, CryptoStreamMode.Write)
Dim
bytearrayinput
As
Byte
() =
New
Byte
(fsInput.Length - 1) {}
fsInput.Read(bytearrayinput, 0, bytearrayinput.Length)
cryptostream1.Write(bytearrayinput, 0, bytearrayinput.Length)
cryptostream1.Close()
fsInput.Close()
fsCiphered.Close()
Dim
fsread
As
New
FileStream(
"
c:\ciphered.txt"
, FileMode.Open, FileAccess.Read
)
Dim
cryptostream2
As
New
CryptoStream(fsread, des2, CryptoStreamMode.Read)
Dim
fsEnciphered
As
New
StreamWriter(
"
c:\enciphered.txt
"
)
fsEnciphered.Write(
New
StreamReader(cryptostream2).ReadToEnd())
fsEnciphered.Flush()
fsEnciphered.Close()
End
Sub
End
Class
The code in Listing 22.36 uses the SHA1 algorithm to compute the hash value of a given string.
Listing 22.36: Hash1.VB, Hashing a String Using SHA-1 Algorithm
Imports
System.IO
Imports
System.Security
Imports
System.Security.Cryptography
Public
Class
Class1
Shared
Sub
Main(
ByVal
args
As
String
())
Dim
str1
As
[String] =
"MCBinc"
Dim
char1a
As
[Char]() = str1.ToCharArray()
Dim
byte1a
As
[Byte]() =
New
[Byte](char1a.Length - 1) {}
For
i
As
Integer
= 0
To
byte1a.Length - 1
byte1a(i) =
CType
(AscW(char1a(i)), [Byte])
Next
' create hash value from str1 using SHA1 instance
' returned by CryptoConfig
Dim
hash1
As
Byte
() =
DirectCast
(CryptoConfig.CreateFromName(
"SHA1"
), HashAlgorithm
.ComputeHash(byte1a)
' or you can use directly created instance of the SHA1 class
' byte[] hash1 = (new SHA1CryptoServiceProvider()).ComputeHash(byte1a );
Console.WriteLine(str1 &
" hashed Value is <"
& BitConverter.ToString(hash1) &
">"
)
Console.ReadLine()
End
Sub
End
Class
Output Window
Conclusion
Hope this article would have helped you in understanding System.Security.Cryptography Namespace in VB.NET.
Login
to add your contents and source code to this article
share this article :
System.Security.Cryptography Namespace in VB.NET
Tags:
Namespace
,
NETSystem.Security.Cryptography Namespace in VB.NET
,
System.Security.Cryptography
The Windows Registry in VB.NET: Part 3
Tags:
VB.NET
,
Windows Registry
,
Windows Registry in VB.NET
Related Articles
System.Security.Cryptography.Xml Namespace in VB.NET
Cryptography in Microsoft .NET Part 1: Encryption
XML Signature in .NET
How to maintain a CodeGroup in Security Policy at runtime?
Exploring Security in .NET: Part I
post comment
TOP LEADERS
View All
TRENDING UP
Use of Excel.AddUnique Method in MS Excel to Display Unique Numbers in Ranges
Use of PPT.ApplyTheme.BackgroundStyle in MS PowerPoint 2010 to Apply Themes & Backgrounds
Use of PPT.InteractWithChartLocation in MS PowerPoint 2010 to Change Chart Locations
Simple Web Report With Pivot Table and Linq to Entity
Print A Chart into a Byte Stream
Using New Audio Player Class With VB.NET
Display Top Ten Percent Item and bottom Ten percent Item
Use of PPT.ConvertTextToSmartArt in MS PowerPoint 2010 to Convert Text into SmartArt
How to Find Backup Folder Data Location Using GetSpecialLocation in MS OneNote 2010
Calendar Control In WPF
View All
Sponsored by
Become a Sponsor
MOST LIKED ARTICLE
Web based Chat application in VB.NET
Scroll text using timer in VB.NET
Input Controls in ASP.Net
Finding the first and last day of the month in VB.NET
Loading a Form Icon in VB.NET
TAG CLOUD
.NET
ADO.NET
app_themes
ASP.NET
C
C#
Database
Datagrid
Design
DirectoryServices
games
GridView
Images
jquery
MVC
Silverlight
Silverlight 5
Thread
try
tutorials
VB.NET
WCF
Windows Forms
WPF
XML
PREMIUM SPONSORS
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Sponsored by
Become a Sponsor