Generate Symmetric Algorithm Key and String : Symmetric Algorithm « Development « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Development » Symmetric AlgorithmScreenshots 
Generate Symmetric Algorithm Key and String
Generate Symmetric Algorithm Key and String

Imports System.Security.Cryptography
Imports System.Text
Imports System.IO
Imports System
Imports Microsoft.VisualBasic.ControlChars

Public Class SymKey
    Public Shared Sub Main(ByVal CmdArgs() As String)
        Dim algo() As String = {"DES""RC2""Rijndael""TripleDES"}

        Dim keyStringDeclare As StringBuilder = New StringBuilder
        Dim ivz As StringBuilder = New StringBuilder
        keyStringDeclare.Append("Dim b64Keys() As String = { _" + VbCrLf)
        ivz.Append(vbCrLf + "Dim b64IVs() As String = { _" + vbCrLf)

        Dim comma As String = ", _" + vbCrLf

        For i As Integer = To 3
            Dim sa As SymmetricAlgorithm = SymmetricAlgorithm.Create(algo(i))
            sa.GenerateIV()
            sa.GenerateKey()
            Dim Key As String
            Dim IV As String
            Key = Convert.ToBase64String(sa.Key)
            IV = Convert.ToBase64String(sa.IV)
            keyStringDeclare.AppendFormat(Tab + """" + Key + """" + comma)
            ivz.AppendFormat(Tab + """" + IV + """" + comma)
            If i = Then comma = " "
        Next i

        keyStringDeclare.Append("}")
        ivz.Append("}")
        Console.WriteLine(keyStringDeclare.ToString())
        Console.WriteLine(ivz.ToString())
    End Sub
End Class
           
       
Related examples in the same category
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.