Neco mam blbe, ale co? Vypisuje tuto chybu: System.Security.Cryptography.CryptographicException was unhandled Message="Specified initialization vector (IV) does not match the block size for this algorithm." Source="mscorlib" kod:
Private keyb() As Byte = StrToByteArray("neco1")
Private ivb() As Byte = StrToByteArray("neco2")
Public Function StrToByteArray(ByVal str As String) As Byte()
Dim encoding As New System.Text.ASCIIEncoding()
Return encoding.GetBytes(str)
End Function 'StrToByteArray
Public Function ByteToStrArray(ByVal dBytes() As Byte) As String
Dim enc As New System.Text.ASCIIEncoding()
Return enc.GetString(dBytes)
End Function
Public Function EncodeString(ByVal str$) As String
Dim outStr As String
' Set up the streams and stuff
Dim ms As New MemoryStream()
Dim rv As New System.Security.Cryptography.RijndaelManaged()
'***** nasleduje chyba *****
Dim cs As New Cryptography.CryptoStream(ms, rv.CreateEncryptor(keyb, ivb), System.Security.Cryptography.CryptoStreamMode.Write)
Dim p() As Byte = Encoding.ASCII.GetBytes(str.ToCharArray())
Dim encodedBytes() As Byte
Try
cs.Write(p, 0, p.Length) ' write to stream as encrypted data
cs.FlushFinalBlock()
encodedBytes = ms.ToArray ' Convert the stream to something we can use
Catch ex As Exception
Finally
ms.Close()
cs.Close()
End Try
outStr = Convert.ToBase64String(encodedBytes)
Return outStr
End Function
Sub main()
Dim l As String = EncodeString("dddeeeffff123456789")
End Sub
|