cyberdeminout
Programmer
I have converted following C# script( to vb.net. Can anyone let me know vb.net script is same as c#? Why am asking is am not getting fixed length Unique ID.
Any help greatly appreicated.
C#:
private string GetUniqueKey()
{
int maxSize = 8 ;
char[] chars = new char[62];
string a;
a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
chars = a.ToCharArray();
int size = maxSize ;
byte[] data = new byte[1];
RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider();
crypto.GetNonZeroBytes(data) ;
size = maxSize ;
data = new byte[size];
crypto.GetNonZeroBytes(data);
StringBuilder result = new StringBuilder(size) ;
foreach(byte b in data )
{ result.Append(chars[b % (chars.Length - 1)]); }
return result.ToString();
}
VB.NET
Function GetUniqueKey()
Dim MaxSize As Integer = 8
Dim chars(62) As Char
Dim a As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
chars = a.ToCharArray()
Dim size As Integer = MaxSize
Dim data(size) As Byte
Dim crypt As New RNGCryptoServiceProvider
crypt.GetNonZeroBytes(data)
Dim result As New StringBuilder(MaxSize)
Dim b As Byte
For Each b In data
result.Append(chars(b Mod (chars.Length - 1)))
Next
Console.WriteLine(result.ToString)
Return result.ToString()
End Function
Any help greatly appreicated.
C#:
private string GetUniqueKey()
{
int maxSize = 8 ;
char[] chars = new char[62];
string a;
a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
chars = a.ToCharArray();
int size = maxSize ;
byte[] data = new byte[1];
RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider();
crypto.GetNonZeroBytes(data) ;
size = maxSize ;
data = new byte[size];
crypto.GetNonZeroBytes(data);
StringBuilder result = new StringBuilder(size) ;
foreach(byte b in data )
{ result.Append(chars[b % (chars.Length - 1)]); }
return result.ToString();
}
VB.NET
Function GetUniqueKey()
Dim MaxSize As Integer = 8
Dim chars(62) As Char
Dim a As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
chars = a.ToCharArray()
Dim size As Integer = MaxSize
Dim data(size) As Byte
Dim crypt As New RNGCryptoServiceProvider
crypt.GetNonZeroBytes(data)
Dim result As New StringBuilder(MaxSize)
Dim b As Byte
For Each b In data
result.Append(chars(b Mod (chars.Length - 1)))
Next
Console.WriteLine(result.ToString)
Return result.ToString()
End Function