oregon ha scritto:
Senza vedere il codice?
Perché posti più volte la stessa domanda?
e questo è il codice:
Private Sub Button11_Click(sender As System.Object, e As System.EventArgs) Handles Button11.Click
Try
Dim original As String = "Here is some data to encrypt!"
' Create a new instance of the RijndaelManaged
' class. This generates a new key and initialization
' vector (IV).
Dim Key As Byte() = System.Text.Encoding.Unicode.GetBytes("iQe8hgLqq6UHvBQ4uLElgWs8dVrGylkw22Sy9ZlHVO4=")
Dim IV As Byte() = System.Text.Encoding.Unicode.GetBytes("8yCa8YjZMy7yPO2Hj50vxQ==")
Using myRijndael As New RijndaelManaged()
myRijndael.GenerateKey()
myRijndael.GenerateIV()
' Encrypt the string to an array of bytes.
'Dim encrypted As Byte() = EncryptStringToBytes(original, myRijndael.Key, myRijndael.IV)
Dim encrypted As Byte() = EncryptStringToBytes(original, Key, IV)
' Decrypt the bytes to a string.
'Dim roundtrip As String = DecryptStringFromBytes(encrypted, myRijndael.Key, myRijndael.IV)
Dim roundtrip As String = DecryptStringFromBytes(encrypted, Key, IV)
'Display the original data and the decrypted data.
Console.WriteLine("Original: {0}", original)
Console.WriteLine("Round Trip: {0}", roundtrip)
End Using
Catch ex As Exception
Console.WriteLine("Error: {0}", ex.Message)
End Try
End Sub
Function EncryptStringToBytes(ByVal plainText As String, ByVal Key() As Byte, ByVal IV() As Byte) As Byte()
' Check arguments.
If plainText Is Nothing OrElse plainText.Length <= 0 Then
Throw New ArgumentNullException("plainText")
End If
If Key Is Nothing OrElse Key.Length <= 0 Then
Throw New ArgumentNullException("Key")
End If
If IV Is Nothing OrElse IV.Length <= 0 Then
Throw New ArgumentNullException("IV")
End If
Dim encrypted() As Byte
' Create an RijndaelManaged object
' with the specified key and IV.
Using rijAlg As New RijndaelManaged()
'rijAlg.Key = Key
'rijAlg.IV = IV
' Create an encryptor to perform the stream transform.
Dim encryptor As ICryptoTransform = rijAlg.CreateEncryptor(Key, IV)
' Create the streams used for encryption.
Using msEncrypt As New MemoryStream()
Using csEncrypt As New CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)
Using swEncrypt As New StreamWriter(csEncrypt)
'Write all data to the stream.
swEncrypt.Write(plainText)
End Using
encrypted = msEncrypt.ToArray()
End Using
End Using
End Using
' Return the encrypted bytes from the memory stream.
Return encrypted
End Function 'EncryptStringToBytes
GRAZIE