Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Cryptography

Cryptography

Scheduled Pinned Locked Moved Visual Basic
questiongraphicssecuritycryptographyperformance
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mikasa
    wrote on last edited by
    #1

    Ok, I've had an Encrypt / Decrypt routine for a year now, but now I'm wondering if I am missing something in it. It seems that anyone with different Languages installed on their PC, the Decrypt cannot decrypt data on a PC with standard English. So, how can I enable my encryption routine to handle Locales?? I know that I need to convert the String into Locale specific data, but I am not sure where in this code. Any help is appreciated.

    Public Class ICrypto
    '<><><><><><><><><><><><><><><>
    #Region "Methods"

    'Function to Return a Key
     \_
    Private Shared Function GetKey(ByVal Data As String, ByVal KeySize As Integer) As Byte()
    	Dim nSize As Integer = CInt((KeySize / 8) - 1)
    	Dim vKey(nSize) As Byte
    	If (Data.Length >= 1) Then
    		Dim lastBound As Integer = Data.Length
    		If (lastBound > nSize) Then lastBound = nSize
    
    		For i As Integer = 0 To lastBound - 1
    			vKey(i) = Convert.ToByte(Data.Chars(i))
    		Next
    	End If
    
    	Return vKey
    End Function
    
    'Function to Get the Initialization Vector
     \_
    Private Shared Function GetIV(ByVal Data As String, ByVal BlockSize As Integer) As Byte()
    	Dim nSize As Integer = CInt((BlockSize / 8) - 1)
    	Dim vVector(nSize) As Byte
    	If (Data.Length >= 1) Then
    		Dim lastBound As Integer = Data.Length
    		If (lastBound > nSize) Then lastBound = nSize
    		For i As Integer = 0 To lastBound - 1
    			vVector(i) = Convert.ToByte(Data.Chars(i))
    		Next
    	End If
    
    	Return vVector
    End Function
    
    'Function to Encrypt Data
     \_
    Public Shared Function Encrypt(ByVal Data As String, ByVal Password As String, Optional ByVal ConvertToBase64 As Boolean = True) As String
    	Dim provCrypto As Cryptography.SymmetricAlgorithm
    	Dim mEncryptor As ICryptoTransform
    	Dim stCrypto As Cryptography.CryptoStream
    	Dim stMemory As IO.MemoryStream, stWriter As IO.StreamWriter
    	Dim vData() As Byte
    	Dim sData As String
    
    	'Exit if there is no Data
    	If (IsNothing(Data)) Then Return String.Empty
    	If (Data.Equals(String.Empty)) Then Return String.Empty
    
    	Try
    		'Initialize the Crypto Provider (3DES)
    		provCrypto = Cryptography.TripleDES.Create()
    		provCrypto.KeySize = 128
    		provCrypto.BlockSize = 64
    		provCrypto.Mode = CipherMode.CBC
    		provCrypto.Padding = PaddingMode.PKCS7
    
    		'Initialize the Memory Stream and Encrypt the Data
    		vData = ConvertStringToBytes(Data)
    		stMemory = New IO.MemoryStream
    		mEncryptor = provCry
    
    A 1 Reply Last reply
    0
    • M mikasa

      Ok, I've had an Encrypt / Decrypt routine for a year now, but now I'm wondering if I am missing something in it. It seems that anyone with different Languages installed on their PC, the Decrypt cannot decrypt data on a PC with standard English. So, how can I enable my encryption routine to handle Locales?? I know that I need to convert the String into Locale specific data, but I am not sure where in this code. Any help is appreciated.

      Public Class ICrypto
      '<><><><><><><><><><><><><><><>
      #Region "Methods"

      'Function to Return a Key
       \_
      Private Shared Function GetKey(ByVal Data As String, ByVal KeySize As Integer) As Byte()
      	Dim nSize As Integer = CInt((KeySize / 8) - 1)
      	Dim vKey(nSize) As Byte
      	If (Data.Length >= 1) Then
      		Dim lastBound As Integer = Data.Length
      		If (lastBound > nSize) Then lastBound = nSize
      
      		For i As Integer = 0 To lastBound - 1
      			vKey(i) = Convert.ToByte(Data.Chars(i))
      		Next
      	End If
      
      	Return vKey
      End Function
      
      'Function to Get the Initialization Vector
       \_
      Private Shared Function GetIV(ByVal Data As String, ByVal BlockSize As Integer) As Byte()
      	Dim nSize As Integer = CInt((BlockSize / 8) - 1)
      	Dim vVector(nSize) As Byte
      	If (Data.Length >= 1) Then
      		Dim lastBound As Integer = Data.Length
      		If (lastBound > nSize) Then lastBound = nSize
      		For i As Integer = 0 To lastBound - 1
      			vVector(i) = Convert.ToByte(Data.Chars(i))
      		Next
      	End If
      
      	Return vVector
      End Function
      
      'Function to Encrypt Data
       \_
      Public Shared Function Encrypt(ByVal Data As String, ByVal Password As String, Optional ByVal ConvertToBase64 As Boolean = True) As String
      	Dim provCrypto As Cryptography.SymmetricAlgorithm
      	Dim mEncryptor As ICryptoTransform
      	Dim stCrypto As Cryptography.CryptoStream
      	Dim stMemory As IO.MemoryStream, stWriter As IO.StreamWriter
      	Dim vData() As Byte
      	Dim sData As String
      
      	'Exit if there is no Data
      	If (IsNothing(Data)) Then Return String.Empty
      	If (Data.Equals(String.Empty)) Then Return String.Empty
      
      	Try
      		'Initialize the Crypto Provider (3DES)
      		provCrypto = Cryptography.TripleDES.Create()
      		provCrypto.KeySize = 128
      		provCrypto.BlockSize = 64
      		provCrypto.Mode = CipherMode.CBC
      		provCrypto.Padding = PaddingMode.PKCS7
      
      		'Initialize the Memory Stream and Encrypt the Data
      		vData = ConvertStringToBytes(Data)
      		stMemory = New IO.MemoryStream
      		mEncryptor = provCry
      
      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      System.Globalization.CultureInfo http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationcultureinfoclasstopic.asp

      M 1 Reply Last reply
      0
      • A Anonymous

        System.Globalization.CultureInfo http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationcultureinfoclasstopic.asp

        M Offline
        M Offline
        mikasa
        wrote on last edited by
        #3

        Ok, well I knew I needed the CultureInfo Class...but I have no idea how to go about using it! I guess I will try to create an InvariantCulture and set it to the Current Culture of the Thread. I will save the existing Culture first so I can restore it later. Does anyone have an example of this? :wtf:

        A 2 Replies Last reply
        0
        • M mikasa

          Ok, well I knew I needed the CultureInfo Class...but I have no idea how to go about using it! I guess I will try to create an InvariantCulture and set it to the Current Culture of the Thread. I will save the existing Culture first so I can restore it later. Does anyone have an example of this? :wtf:

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          Look here in section 3.3 http://www.gotdotnet.com/team/vb/VBSampleGuidelines.htm

          1 Reply Last reply
          0
          • M mikasa

            Ok, well I knew I needed the CultureInfo Class...but I have no idea how to go about using it! I guess I will try to create an InvariantCulture and set it to the Current Culture of the Thread. I will save the existing Culture first so I can restore it later. Does anyone have an example of this? :wtf:

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            and here is another reference http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcustomcasemappingssortingrules.asp

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups