Ask a questionAsk a question
 

AnswerDoes VB 2008 Express Edition have?

  • Wednesday, November 04, 2009 2:29 PMDeMolay8613 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Does it have something built in so that you can encrypt a single form? My program contains a log in form and I want to encrypt just that one form so that no one can find out the password.

Answers

  • Thursday, November 05, 2009 6:11 PMOmie Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    you cannot encrypt code behind the forms. You have to store that password somewhere outsite your program and have it encrypted.

    For that, this simple encryption works great. I had posted it earlier somewhere here

    http://www.codeguru.com/csharp/.net/net_security/encryption/article.php/c10343/


    Thanks

    My BlogMy FacebookYOUR Place to have fun time ! Awesome RPG Action Game
  • Sunday, November 08, 2009 4:11 AMjgalley Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    This should get you going again:

    Imports System
    Imports System.IO
    Imports System.Security.Cryptography
    Imports System.Text
    
    Namespace ConsoleApplication1
        Class Program
            Private Shared Sub Main(ByVal args As String())
                Console.WriteLine("Enter Password:")
                Dim testPassword As [String] = Console.ReadLine()
                Dim testEncryption As [String] = EncryptString(testPassword)
                
                Console.WriteLine()
                Console.WriteLine([String].Format("Password {0} encrypts to {1}", testPassword, testEncryption))
                
                If validPassword.Equals(testEncryption) Then
                    Console.WriteLine("you are in")
                Else
                    Console.WriteLine("bad password")
                End If
            End Sub
            
            Private Shared rgbIV As Byte() = Encoding.ASCII.GetBytes("asdfikygresonlhz")
            Private Shared key As Byte() = Encoding.ASCII.GetBytes("a;lsfiasdklixk,adfmasdl;k';asdfi")
    
            ' matches "brothers"
            Private Shared validPassword As String = "K8f6CqTHUdlhYGiX+IfuXQ=="
    
            Public Shared Function EncryptString(ByVal ClearText As [String]) As [String]
                Dim encryptedText As [String] = [String].Empty
                
                Using ms As New MemoryStream()
                    Dim rijn As SymmetricAlgorithm = SymmetricAlgorithm.Create()
                    Using cs As New CryptoStream(ms, rijn.CreateEncryptor(key, rgbIV), CryptoStreamMode.Write)
                        Dim clearTextBytes As Byte() = Encoding.UTF8.GetBytes(ClearText)
                        cs.Write(clearTextBytes, 0, clearTextBytes.Length)
                    End Using
                    encryptedText = Convert.ToBase64String(ms.ToArray())
                End Using
                
                Return encryptedText
            End Function
            
        End Class
    End Namespace
    

     

All Replies

  • Wednesday, November 04, 2009 2:59 PMjgalley Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Sure,

    Depending on how "secure" you want you could do anything from home grow your own ASCII rotation cypher or use a proper one.
    Here is an example of encrypting the contents of a file, though it could just as easily be used to encrypt a string.


  • Wednesday, November 04, 2009 3:42 PMGanesh Ranganathan - Bangalore, India Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Does it have something built in so that you can encrypt a single form? My program contains a log in form and I want to encrypt just that one form so that no one can find out the password.

    There isnt any need to encrypt the whole form (even if it is possible).

    Instead encrpyt the password and store it in the database. When the user enters the password in the form, encrpyt it and compare it withe the value in DB.
    Ganesh Ranganathan
    [Please mark the post as answer if it answers your question]
    blog.ganeshzone.net
  • Wednesday, November 04, 2009 9:24 PMDeMolay8613 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Right now my password looks like this:

    Dim myPassword As String = "brothers"
    
    The entire form doesn't have to be encrypted I just need enough of it encrypted so that no one can find out the password.
  • Thursday, November 05, 2009 5:59 PMDeMolay8613 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Does it have something built in so that you can encrypt a single string My program contains a log in form and I want to encrypt the string that contains the password so that no one can find out the password. My desktop is XP and my laptop is Vista I do half of my programming from one computer and half from the other that's why I'm asking if it has something built in that can do this.

  • Thursday, November 05, 2009 6:11 PMOmie Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    you cannot encrypt code behind the forms. You have to store that password somewhere outsite your program and have it encrypted.

    For that, this simple encryption works great. I had posted it earlier somewhere here

    http://www.codeguru.com/csharp/.net/net_security/encryption/article.php/c10343/


    Thanks

    My BlogMy FacebookYOUR Place to have fun time ! Awesome RPG Action Game
  • Thursday, November 05, 2009 6:18 PMOmie Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    on second thought, you could store MD5 hash of some string in your program in some variable and when user enters password, MD5 it and compare with stored hash.

    anyway..



    Thanks

    My BlogMy FacebookYOUR Place to have fun time ! Awesome RPG Action Game
  • Thursday, November 05, 2009 6:21 PMPaul P Clement IVMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
  • Saturday, November 07, 2009 11:09 PMDeMolay8613 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    My desktop uses XP and my laptop uses Vista. My program is on the laptop and I noticed when I went to that Microsoft link that is only good for XP computers. Is there way to encrypt on a Vista computer? Also the reason I want to encrypt a whole form is because the organization that I am making this for they don't want the information in the program to be available for just anyone to access it and as of right now if you were to right click the program when you publish it and click open with Notepad then you can view ALL of the text that is in the program. Therefore, I need to encrypt 2 forms not just one.

  • Sunday, November 08, 2009 4:11 AMjgalley Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    This should get you going again:

    Imports System
    Imports System.IO
    Imports System.Security.Cryptography
    Imports System.Text
    
    Namespace ConsoleApplication1
        Class Program
            Private Shared Sub Main(ByVal args As String())
                Console.WriteLine("Enter Password:")
                Dim testPassword As [String] = Console.ReadLine()
                Dim testEncryption As [String] = EncryptString(testPassword)
                
                Console.WriteLine()
                Console.WriteLine([String].Format("Password {0} encrypts to {1}", testPassword, testEncryption))
                
                If validPassword.Equals(testEncryption) Then
                    Console.WriteLine("you are in")
                Else
                    Console.WriteLine("bad password")
                End If
            End Sub
            
            Private Shared rgbIV As Byte() = Encoding.ASCII.GetBytes("asdfikygresonlhz")
            Private Shared key As Byte() = Encoding.ASCII.GetBytes("a;lsfiasdklixk,adfmasdl;k';asdfi")
    
            ' matches "brothers"
            Private Shared validPassword As String = "K8f6CqTHUdlhYGiX+IfuXQ=="
    
            Public Shared Function EncryptString(ByVal ClearText As [String]) As [String]
                Dim encryptedText As [String] = [String].Empty
                
                Using ms As New MemoryStream()
                    Dim rijn As SymmetricAlgorithm = SymmetricAlgorithm.Create()
                    Using cs As New CryptoStream(ms, rijn.CreateEncryptor(key, rgbIV), CryptoStreamMode.Write)
                        Dim clearTextBytes As Byte() = Encoding.UTF8.GetBytes(ClearText)
                        cs.Write(clearTextBytes, 0, clearTextBytes.Length)
                    End Using
                    encryptedText = Convert.ToBase64String(ms.ToArray())
                End Using
                
                Return encryptedText
            End Function
            
        End Class
    End Namespace