|
Please check the following sample, I think you can also include null strings checking. I hope it works out for you.
Imports System.Text
Imports System.Security.Cryptography
Public Class Encryption
#Region "Public Routines"
const ENCRYPT_KEY AS STRING = "TEST"
const ENCRYPT_VECTOR AS STRING = "CODEPRJT"
Public Shared Function ToBase64(ByVal sDataToEncrypt As String) As String
Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream
Dim key As Byte() = Encoding.Default.GetBytes(ENCRYPT_KEY.PadRight(24, Chr(0)))
Dim Vector As Byte() = Encoding.Default.GetBytes(ENCRYPT_VECTOR.PadRight(8, Chr(0)))
Dim des As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
Dim cryptoStream As CryptoStream = New CryptoStream(stream, des.CreateEncryptor(key, Vector), CryptoStreamMode.Write)
Dim Input() As Byte = Encoding.Default.GetBytes(sDataToEncrypt)
cryptoStream.Write(Input, 0, Input.Length)
cryptoStream.FlushFinalBlock()
Return Convert.ToBase64String(stream.ToArray())
End Function
Public Shared Function ToBase32(ByVal sDataToDecrypt As String) As String
Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream
Dim key As Byte() = Encoding.Default.GetBytes(ENCRYPT_KEY.PadRight(24, Chr(0)))
Dim Vector As Byte() = Encoding.Default.GetBytes(ENCRYPT_VECTOR.PadRight(8, Chr(0)))
Dim des As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
Dim cryptoStream As CryptoStream = New CryptoStream(stream, des.CreateDecryptor(key, Vector), CryptoStreamMode.Write)
Dim Input() As Byte = Convert.FromBase64String(sDataToDecrypt)
cryptoStream.Write(Input, 0, Input.Length)
cryptoStream.FlushFinalBlock()
Return Encoding.Default.GetString(stream.ToArray())
End Function
#End Region
End Class
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
its throws an error message :
Specified key is a known weak key for 'TripleDES' and cannot be used
Arindam Banerjee
Sr. Software Developer
Rance Computer Pvt Ltd.
Kolkata (India)
|
|
|
|
|
I had the same problem but when I change the keys it worked out. Actually teh code doesn't belong to me. Try to use different string keys.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
I need the code for accessing the IMEI number of PDA using windows mobile application..
Regards
Varun Prakash
|
|
|
|
|
Denied. This site does not exist to just hand over code. We'll help you write your own, but noone is going to write it for you. If you want prewritten code, you'll have to visit RentACoder.com and take your chances.
|
|
|
|
|
Hi all...
Suggest me how can I delete 2 or 3 lines from the mid or any location of file without changing other lines of file.
Thanks.
Gagan
|
|
|
|
|
A brute-force way could be that you use File.ReadAllLines[^] which gives you an array of string, then remove the unwanted elements and then use WriteAllLines[^] to write the contents.
Another way would be to use TextReader.ReadLine[^], loop through the rows and if you want to save the row, use StreamWriter class to write the data. For an example, have a look at the example in TextWriter[^].
|
|
|
|
|
Thanks for your suggestion.
Gagan
|
|
|
|
|
--> i want to send form-events from the form to a class library... which i want to handle them in the class library... but i cannot find any way to do this...
e.g: keypress event of a textbox.....
--> How can i handle events in a class library..?
J A Nasir K
modified on Saturday, February 21, 2009 8:38 AM
|
|
|
|
|
You should have event handlers defined in your class library. You register those event handlers with the Form events. When the event is fired(from the Form), all event handlers registered will be invoked. Since your class library had registered, its event handler will also be invoked.
|
|
|
|
|
Hi i have a problem that is making me scratch my head until it hurts.
Hopefully someone can help. Well in my project I have a graph were I plot information from a database. Anyways, when I draw my data to the screen I add each point to an arraylist. I use an arraylist since the number of points can vary. So I have my points drawn on screen so next is were my problem comes in. What I want to happen is when the mouse pointer goes over any of my points on my graph, then a small box pops up with more information. So in my mousemove event I have code as follows
For Each p As Point In myCoordinatesArrayL
gPath.AddEllipse(p.X, p.Y, 30, 30)
If gPath.IsVisible(mouse.X, mouse.Y) Then
'Then make my small window pop up
Else
'Do nothing or close small window if its up
End If
Next
So im taking the points from my arraylist and adding an ellipse to a graphics path. Then I check
the graphics path 'IsVisible' function if the mouse's x and y are over it.
I have mixed results with this so far. Some strange and unexpected things have happened. I can get the window to pop up but sometimes it doesn't. I have done a bit of error checking were I have placed two labels on my form and I increment a number when ever the mouse is not over the points and then increments the other number when the mouse pointer is over the point. This has unexpected results such as when I have only one point on the screen and i move the mouse over the point then both label increment and when i have more than one point on the screen, its works as expected except for the first point on my graph where is produces the same problem.
Hope you can make sense of this. Is there a better way to do what im trying to do. Any suggestions.
Thanks for your help
|
|
|
|
|
You creating an ellipse for every point in the graph every time the mouse moves?? Wouldn't it be easier to just track the mouse movement, mapping it to the closest point in the X axis, then just create the one ellipse to see if the mouse is in it?
Also, the code looks incomplete. Are you Disposing the GraphicsPath you created when you're done with it?? Are you creating a new one every time you iterate through this loop?? You don't need to.
|
|
|
|
|
Hi,
Not sure I know what you mean. So i think that for every point in my arraylist that I should
check its x coordinate against the mouse x coordinate and then if it does , then i should add the ellipse to my graphics path. This is what I've tried but its not really working for me
For Each p As Point In myCoordinatesArrayL
If p.X = mouse.X Then
gPath.AddEllipse(p.X, p.Y, 30, 30)
If gPath.IsVisible(mouse.X, mouse.Y) Then
'code for displaying my window
End If
Else
'do nothing or close my window
End If
Next
I dont have code to dispose the graphicsPath here but in my forms closing method. Is this right
Thanks for your time
|
|
|
|
|
No, you have to do a little math to figure out which point the X coord is NEAREST to on the graph. In your method, the mouse has to be EXACTLY on the point your looking for, not around it.
If you have 3 points on the graph at 50, 75 and 100, you take the mouse X coord, say 80, then check it against the X coord of the points on the graph, plus or minus say 10. Doing the math is FAR faster than creating a graphics path to do the test for you.
For Each p As Point In myCoordinatesArrayL
If p.X - mouse.X <= 1- Then
' You don't even need the GraphicsPath since you just
' found the point you're looking for!
' If you really needed to, you can do the same test for the Y coordinate in here.
End If
Next
|
|
|
|
|
Thats great. Thanks for your help. Never even thought of that. My inexperience is showing anyway.
Thanks again.
|
|
|
|
|
i m student and making a project for my college
it is compulsory tat i make the project in vb6
The project is tat i have to make an application using vb6 in which we just have to mention the file name which we have to search
and click a button and it will search in all computers in lan at once
we dont have to mention any computer name or host name it should take the computer names itself
i have written the code in which i have to mention the hostname plus drive
for eg: \\rng13579076\c$
the alternate way is to search neighbourhood network and i will get all the computers connected in lan but i dont know how to do so
pls guide me!
purvas
modified on Saturday, February 21, 2009 4:07 AM
|
|
|
|
|
spruha369 wrote: for my college
it is compulsory tat i make the project in vb6
VB6 isn't the appropriate choice for students anymore. It's not for sale (only on eBay) and tech support from MS is expensive. There are still some old applications running under VB6 (or even VB4 for that matter), but it would be pointless to learn something that has been proclaimed "dead" last year. Can you ask your teacher why you'll have to learn a dead language? I'd love to hear the reasoning behind it
If you are left with no options but using the old IDE, ask if you're allowed to write some of the logic in a newer language - you could do the hard parts in VB.NET or C# and hook it up to the old application.
Good luck!
I are troll
|
|
|
|
|
Hi,
How can I iterate all of the directories in a specific drive? My patience is exhausted and my hair is all over the table. My aim is to get in and get out evey directory in selected drive. If the directory has some files with the extension of (txt) I should put their name into listview.
Currently I can read all 1st child directories under the specific drive. But we don't know how many child directories has the targeted one. Therefore we should be able to skip from one to another one. When there is no directory and no file we should go back to their parent and continue to process until the last child directory gets done.
I am seeking a sample with use of directoryinfo. I didn't want to put my code here because it is quite long.
I would really appreciate it if you know the method or having the code.
Thanks.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
|
Thanks
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
If you want every directory on the drive, you will need to use recursion. Recursion basically looks something like this:
Public Sub CheckDirectories(ByVal root As IO.DirectoryInfo)
For Each file In root.GetFiles("*.txt")
'process the file
Next
For Each subDir In root.GetDirectories()
CheckDirectories(root)
Next
End Sub
which you then call with the DirectoryInfo for the selected drive to start the whole thing.
|
|
|
|
|
Thanks.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Hi Gideon
I am interested with your approach, I know what do you mean by "something like this", it needs a little fine tuning.
I had this code which is stayed in forever loop and I could not tell why?
' Command Click
Dim RootDir As New IO.DirectoryInfo("C:\MyFolder")
Call Module1.CheckDirectories(RootDir)
' Module1.CheckDirectories
Public Sub CheckDirectories(ByVal root As IO.DirectoryInfo)
For Each file In root.GetFiles("*.txt")
Debug.Print(file.Name) 'process the file
Next
For Each subDir In root.GetDirectories()
CheckDirectories(root)
Next
End Sub
TIA
Samir R. Ibrahim
|
|
|
|
|
Hi Samir,
I assume you are seeing the names of the files within c:\MyFolder displayed ad infinitum. Take a good look at the actual recursive call within the method, i.e. the point where CheckDirectories calls itself, and think what the parameter should be for that call.
Step through it with the debugger if you still can't see what's wrong.
Alan.
|
|
|
|
|
Hi Alan
Alan N wrote: and think what the parameter should be for that call.
subDir
I know that, but I was testing you.
Thanks for pointing to it
Samir R. Ibrahim
|
|
|
|