|
I tried the following code for encrypting and decrypting. I have encrypted a string in button1_click event. The problem here is that I cant able to pass the encrypted value in button2_click event...
Can anyone help me out to find what the problem here is????
Imports System
Imports System.Security.Cryptography
Imports System.IO
Partial Class _Default
Inherits System.Web.UI.Page
Public original As String
Public roundtrip As String
Public encrypted As Byte()
Public myRijndael As New RijndaelManaged()
Function encryptStringToBytes_AES(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("Key")
End If
Dim msEncrypt As MemoryStream = Nothing
Dim csEncrypt As CryptoStream = Nothing
Dim swEncrypt As StreamWriter = Nothing
Dim aesAlg As RijndaelManaged = Nothing
Try
aesAlg = New RijndaelManaged()
aesAlg.Key = Key
aesAlg.IV = IV
Dim encryptor As ICryptoTransform = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV)
msEncrypt = New MemoryStream()
csEncrypt = New CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)
swEncrypt = New StreamWriter(csEncrypt)
swEncrypt.Write(plainText)
Finally
If Not (swEncrypt Is Nothing) Then
swEncrypt.Close()
End If
If Not (csEncrypt Is Nothing) Then
csEncrypt.Close()
End If
If Not (msEncrypt Is Nothing) Then
msEncrypt.Close()
End If
If Not (aesAlg Is Nothing) Then
aesAlg.Clear()
End If
End Try
Return msEncrypt.ToArray()
End Function
Function decryptStringFromBytes_AES(ByVal cipherText() As Byte, ByVal Key() As Byte, ByVal IV() As Byte) As String
' Check arguments.
If cipherText Is Nothing OrElse cipherText.Length <= 0 Then
Throw New ArgumentNullException("cipherText")
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("Key")
End If
Dim msDecrypt As MemoryStream = Nothing
Dim csDecrypt As CryptoStream = Nothing
Dim srDecrypt As StreamReader = Nothing
Dim aesAlg As RijndaelManaged = Nothing
Dim plaintext As String = Nothing
Try
aesAlg = New RijndaelManaged()
aesAlg.Key = Key
aesAlg.IV = IV
Dim decryptor As ICryptoTransform = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV)
msDecrypt = New MemoryStream(cipherText)
csDecrypt = New CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)
srDecrypt = New StreamReader(csDecrypt)
plaintext = srDecrypt.ReadToEnd()
Finally
If Not (srDecrypt Is Nothing) Then
srDecrypt.Close()
End If
If Not (csDecrypt Is Nothing) Then
csDecrypt.Close()
End If
If Not (msDecrypt Is Nothing) Then
msDecrypt.Close()
End If
If Not (aesAlg Is Nothing) Then
aesAlg.Clear()
End If
End Try
Return plaintext
End Function
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
original = TextBox1.Text
encrypted = encryptStringToBytes_AES(original, myRijndael.Key, myRijndael.IV)
// "Trying to pass this encrypted value in button2_click event"
TextBox2.Text = Convert.ToBase64String(encrypted)
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
roundtrip = decryptStringFromBytes_AES(encrypted, myRijndael.Key, myRijndael.IV) //"shows encrypted value is nothing"
TextBox2.Text = roundtrip
End Sub
End Class
|
|
|
|
|
Hi,
The simplest method of doing this is change the asci value of each character in the string to encrypt and to decrypt string convert acsi to its orignal value.
Hope this helps
|
|
|
|
|
Hi,
can u tell me how to convert strings like
12/06/2020 ,12-06-2007 etc in date format.
ex: 12/06/2007-------> 12-Dec-2006
12-06-2007-------> 12-Dec-2006
thanks & regards
|
|
|
|
|
Check this out _ I never used it myself - but stumbled over it over the last few days when trying to fix my late binding issue ..
It copied out of the Help index
Imports System
Public Class ChangeTypeTest
Public Shared Sub Main()
Dim d As [Double] = - 2.345
Dim i As Integer = CInt(Convert.ChangeType(d, GetType(Integer)))
Console.WriteLine("The double value {0} when converted to an int becomes {1}", d, i)
Dim s As String = "12/12/98"
Dim dt As DateTime = CType(Convert.ChangeType(s, GetType(DateTime)), DateTime)
Console.WriteLine("The string value {0} when converted to a Date becomes {1}", s, dt)
End Sub 'Main
End Class 'ChangeTypeTest
|
|
|
|
|
DateTime.TryParseExact method or TryParse/Parse with the right culture
|
|
|
|
|
Hi,
This is perfect
Date.Today.ToString("d-MMM-yyyy") to get the way we want.
u have to use , dd-M-YY (Format) like this for this search in net .
dvs
|
|
|
|
|
Hi,
Try this one
<br />
Dim d As Date<br />
Dim s As String<br />
s = "17-12-2007"<br />
d = CType(s, Date)<br />
s = Format(d, "d MMMM yyyy")<br />
MsgBox(s)<br />
Hope this helps
|
|
|
|
|
i am converting a consloe application from vb to c#,
can anybody help me here how to do this efficiently...
am stuck with somekeyword... like
VB.Command()
.... and one more thing what will be equivalet to module in case of C#
T@SU
|
|
|
|
|
tasumisra wrote: am stuck with somekeyword... like
VB.Command()
No such thing in the VB.NET language. THis has to be an instance of some object with a method called Command . It's not in the .NET Base Class Library, so this has to be some 3rd party library or some other class that was written in this app.
tasumisra wrote: and one more thing what will be equivalet to module in case of C#
Modules are an outdated concept. There is no equivilent in C#, other than converting the code to a class and exposing the methods as static (Shared in VB.NET) methods.
|
|
|
|
|
Hi Guys
I want to change the F4 key on the combo box in vb.net 2005
By default, if the combo box has focus, and you press F4, it will open/drop down.
F4 is already used in my program, is it possible to change the key to for example F5?
Thank you very much.
|
|
|
|
|
there error appear in frist open the vb.net in "location : C:\program files\microsoft visual stdudio 8\common 7\ide \devenv.exe" and the can not run the project
|
|
|
|
|
|
i do this and the same error
|
|
|
|
|
maybe you can give us the error message?
|
|
|
|
|
the error message is"
location : C:\program files\microsoft visual stdudio 8\common 7\ide \devenv.exe
visual studio 2005 has aknown compatiblity issue with version of windows
then i download the "Visual Studio 2005 Service Pack 1 Update for Windows Vista" and appear this error
"the upgrade patch cannot be install by the windows installer service because the program to be upgrade may be missing , or the upgrade patch may update different version of the program . verify that program to be upgraded exists on your computer and you have the correct upgrade patch"
|
|
|
|
|
OK:
first you need the Service Pack 1 (without Update for Vista) and install this (make sure to take the right language).
then you can install the "Service Pack 1 Update for Vista" !
|
|
|
|
|
I've seen people ignore this message and continue on without any adverse affects.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
How can i add a text and a corresponding value for it?
When i fill date to a combox from database,i need to get the corresponding value ie primary key of the selected text when i select a item from combobox.
Thanks
Yesu
|
|
|
|
|
Each Item of a combobox have Text and Value associated.For example
Dim oItem As ListItem = New ListItem()
oItem.Text = "your text"
oItem.Value = "Some ID"
you can use the SelectedValue property of a drop down to get the selected value
|
|
|
|
|
Hi,
I have one query that
"SELECT Incharge_Name, COUNT(Incharge_Name) AS [Incharge Name] FROM t_Showroom GROUP BY Incharge_Name"
I declare two arrays
Dim arrValues1() As Integer
Dim arrLabels1() As String
Now I have to assign values of Incharge_Name(int value) to arrValues1 array and Incharge_Name to arrLabels1 array
I am using dataset to retrive the value
Thanks,
sjs4u
|
|
|
|
|
All you have to do is loop that DataTable in your Dataset and assign the values to your array.
Here a link on how to work with arrays [^]
|
|
|
|
|
Can Somebody help me here
I have written an application for two different motion controllers
- The code for each controller is placed in it's own module with identical
subs
Depending on the controller selected it will execute the appropriate code
Here is the problem .. after setting the project to OPTION STRICT = ON
I get the late binding not allowed message and I just can not get it fixed
Below is a sample code that should help understand my issue easier (I l know it's an easy thing - I just can not figure it out)
It's important for me that the Variable [SelectedController] that holds the object to the selected module is accessible throughout the whole project !
PS the code below doesn’t work = The variable [SelectedController] is not accessible outside the subs !
Where I try to call the actual subroutine is where I get the late binding error
Example : SelectedController.test()
Thanks
Georg
Public Module DECLARE_VARAIBLES
Public SelectedController As Object ' selected controller
End Module
Public Class Form1
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SelectedController As New ControllerA
Display_Controller()
End Sub
Public Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim SelectedController As New ControllerB
Display_Controller()
End Sub
Private Sub Display_Controller()
'**************
' HERE IS WHERE I USUALLY RUN INTO MY LATE BINDING ISSUE
SelectedController.test()
End Sub
End Class
Public Class ControllerA
Public Sub test()
MsgBox("running Controller A")
End Sub
End class
Public Class ControllerB
Public Sub test()
MsgBox("running Controller B")
End Sub
End Class
|
|
|
|
|
This is the normal - and desired - result if you try to invoke a method "test" on an boxed object ( indeed you are calling object.test() ).
If you have some classes that each implements the same methods you should use Interfaces like this:
Somewhere outside a class define:
<br />
Public Interface ITest<br />
Sub test()<br />
End Interface<br />
and then in your classes (ControllerA and ControllerB):
<br />
Public Class ControllerA<br />
Implements ITest<br />
Public Sub test()<br />
MsgBox("running Controller A")<br />
End Sub<br />
End Class<br />
(ControllerB similar)
And finally in your Module:
<br />
Public Module DECLARE_VARAIBLES<br />
Public SelectedController As ITest ' selected controller<br />
End Module<br />
-> you will get IntelliSense help and the code will work
|
|
|
|
|
I'm not sure if I'm getting this ...
Am i correct in that Interfaces are intended to be used for code that's exactly the same ?
Public Interface ITest
Sub test()
End Interface
Itest will be the same in both controllerA & controllerB
If this is how it works that that's NOT what I need
I have a user Interface that will call the subs inside to different classes, ControllerA or ControllerB (The SUB NAMES Inside the classes are identical but the code inside the subs will never be!)
I believe it would make my live a lot easier (and Cleaner to maintain ) if I could just call the "same" subs out of my user interface
Sub Jog_X()
SelectedController.jogging
' where SelectedControler.Jog_X will have to point to
'A) ControllerA.Jog_X
'or
'B) ControlerB.Jog_X
end sub
Georg
|
|
|
|
|
Can anyone give me any idea on how to monitor client on a LAN through vb.net
the features like key logging and screenshots are working only on my system
plz tell me how to implement this on multiple systems
|
|
|
|