I supported every answer (well, those here before mine!) Here, as they are all correct.
However, there is a big mistake you make (which I also made v.early on) - DO NOT USE A LINE TO MAKE IV OR KEY !!!
unicode , , , ( - ), , 2 1 - 8 , , - , 8 .
- ASCII, .
RNGCryptoServiceProvider IV Key, , , hex string Base-64 ( hex, ).
, , VS ( CTRL + SHIFT + G, CTRL + SHIFT + H), .Net PRNG :
Public Sub GenerateHexKey()
Dim result As String = InputBox("How many bits?", "Key Generator", 128)
Dim len As Int32 = 128
If String.IsNullOrEmpty(result) Then Return
If System.Int32.TryParse(result, len) = False Then
Return
End If
Dim oldCursor As Cursor = Cursor.Current
Cursor.Current = Cursors.WaitCursor
Dim buff((len / 8) - 1) As Byte
Dim rng As New System.Security.Cryptography.RNGCryptoServiceProvider()
rng.GetBytes(buff)
Dim sb As New StringBuilder(CType((len / 8) * 2, Integer))
For Each b In buff
sb.AppendFormat("{0:X2}", b)
Next
Dim selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection
Dim editPoint As EnvDTE.EditPoint
selection.Insert(sb.ToString())
Cursor.Current = oldCursor
End Sub
, , - - :
public static byte[] FromHexString(this string str)
{
int NumberChars = str.Length;
byte[] bytes = new byte[NumberChars / 2];
for (int i = 0; i < NumberChars; i += 2)
bytes[i / 2] = Convert.ToByte(str.Substring(i, 2), 16);
return bytes;
}
, , , .