Specified key is not a valid size for this algorithm
Hey,Sidder og roder med noget kryptering, men jeg får en Exception når jeg forsøger at kryptere noget.
"Specified key is not a valid size for this algorithm" - ja, det siger jo det hele, men hvordan får jeg nøglen til at være en gyldig størrelse?
Min kode:
Private _password As String
Private _iv As Byte() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
Public Property Password() As String
Get
Return _password
End Get
Set(ByVal value As String)
_password = value
End Set
End Property
Public Sub Encrypt(ByVal name As String, ByVal data As String)
Dim loc As String = String.Format("{0}\{1}.txt", Locations.SafeItemsDirectory, name)
Dim key As Byte() = Encoding.UTF8.GetBytes(_password)
Dim fStream As FileStream = File.Open(loc, FileMode.OpenOrCreate)
Dim RijndaelAlg As Rijndael = Rijndael.Create
RijndaelAlg.Key = key ' Her går det galt
RijndaelAlg.IV = _iv
Dim cStream As New CryptoStream(fStream, RijndaelAlg.CreateEncryptor(), CryptoStreamMode.Write)
Dim sWriter As New StreamWriter(cStream)
sWriter.WriteLine(data)
sWriter.Close()
cStream.Close()
fStream.Close()
End Sub