locked
Where do I download code mentioned in Q 11 - Explain how to encrypt/decrypt a string in .Net RRS feed

Answers

All replies

  • User-271186128 posted

    Hi piyush_varma,

    According to the video, I found it is relate to encrypt/decrypt. Here are some good articles about it, they all include sample, you could refer to them:

    The MD5 hash algorithm: http://msdn.microsoft.com/en-us/library/system.security.cryptography.md5(v=vs.110).aspx

    Advanced Encryption Standard (AES): http://msdn.microsoft.com/en-us/library/system.security.cryptography.aes(v=vs.110).aspx

     The Data Encryption Standard (DES) algorithm: http://msdn.microsoft.com/en-us/library/system.security.cryptography.des(v=vs.110).aspx

    More details about cryptographic services, please refer to the following links:

    http://msdn.microsoft.com/en-us/library/system.security.cryptography(v=vs.110).aspx

    http://msdn.microsoft.com/en-us/library/92f9ye3s(v=vs.110).aspx

    If you have any further questions, please feel free to post in this forum.

    Best Regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 29, 2014 8:20 AM
  • User186512335 posted

    I have found a working C# code here and I needed it in VB.NET. I was able to successfully convert it ias below. I tested for number s from 1 to 1 million.

        Public Function EncryptData(ByVal Message As String, ByVal passphrase As String) As String
    
            Dim Results() As Byte = Nothing
            Dim UTF8 As System.Text.UTF8Encoding = New System.Text.UTF8Encoding()
    
            Dim HashProvider As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
            Dim TDESKey() As Byte = HashProvider.ComputeHash(UTF8.GetBytes(passphrase))
    
            Dim TDESAlgorithm As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
            TDESAlgorithm.Key = TDESKey
            TDESAlgorithm.Mode = CipherMode.ECB
            TDESAlgorithm.Padding = PaddingMode.PKCS7
    
            Dim DataToEncrypt() As Byte = UTF8.GetBytes(Message)
    
            Try
                Dim Encryptor As ICryptoTransform = TDESAlgorithm.CreateEncryptor
                Results = Encryptor.TransformFinalBlock(DataToEncrypt, 0, DataToEncrypt.Length)
            Catch ex As Exception
                Console.WriteLine(ex.ToString)
            Finally
                TDESAlgorithm.Clear()
                HashProvider.Clear()
            End Try
    
            Return Convert.ToBase64String(Results)
    
        End Function
    
        Public Function DecryptData(ByVal Message As String, ByVal passphrase As String) As String
    
            Dim Results() As Byte = Nothing
            Dim UTF8 As System.Text.UTF8Encoding = New System.Text.UTF8Encoding()
    
            Dim HashProvider As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
            Dim TDESKey() As Byte = HashProvider.ComputeHash(UTF8.GetBytes(passphrase))
    
            Dim TDESAlgorithm As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
            TDESAlgorithm.Key = TDESKey
            TDESAlgorithm.Mode = CipherMode.ECB
            TDESAlgorithm.Padding = PaddingMode.PKCS7
    
            Dim DataToDecrypt() As Byte = Convert.FromBase64String(Message)
    
            Try
                Dim Decryptor As ICryptoTransform = TDESAlgorithm.CreateDecryptor
                Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length)
            Catch ex As Exception
                Console.WriteLine(ex.ToString)
            Finally
                TDESAlgorithm.Clear()
                HashProvider.Clear()
            End Try
    
            Return UTF8.GetString(Results)
    
        End Function
    

    Friday, August 29, 2014 6:38 PM