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






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 = 0 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 = 2 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