How to convert MemoryStream string to Hex?

I'm doing some encryption and, normally would return a baes 64 string but it's causing issues with URLs, so we are going to use hex strings instead....but I'm having an issue...

Instead of:
Return Convert.ToBase64String(ms.GetBuffer(), 0, CInt(ms.Length))

I'd like to return a hex string... I need a pointer here....thanks.....


0
Curt_C
12/15/2006 2:26:40 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

4 Replies
682 Views

Similar Articles

[PageSpeed] 5
Get it on Google Play
Get it on Apple App Store

Dim myNumber as integer = 'Get your Number from the buffer

Dim HexString as string = myNumber.tostring("X")


Bryan Sampica
Auction Site StarterKit |
My Blog
0
Freakyuno
12/15/2006 4:43:37 PM

The tough part is the "get your number from the buffer" part.... That's what I don't get/know.


0
Curt_C
12/15/2006 4:47:41 PM

I'm trying to create an example of a memorystream loaded up, so I can see how to get it back out, but I need an example of what would be sitting,  or "should" be sitting in your memory stream, so that I can decode it back to a strongly typed variable.


Bryan Sampica
Auction Site StarterKit |
My Blog
0
Freakyuno
12/15/2006 4:51:03 PM

Its my encryption function....

Public

Shared Function Encrypt(ByVal value As String) As String
    Dim _encoding As UTF8Encoding = New UTF8Encoding
   
Dim KEY_64() As Byte = _encoding.GetBytes("12345678")
   
Dim IV_64() As Byte = _encoding.GetBytes("12345678")
   
If value <> "" Then
       
Dim cryptoProvider As DESCryptoServiceProvider = New DESCryptoServiceProvider()
       
Dim ms As MemoryStream = New MemoryStream()
       
Dim cs As CryptoStream = New CryptoStream(ms, cryptoProvider.CreateEncryptor(KEY_64, IV_64), CryptoStreamMode.Write)
       
Dim sw As StreamWriter = New StreamWriter(cs)
        sw.Write(value)
        sw.Flush()
        cs.FlushFinalBlock()
        ms.Flush()
        'convert back to a string HERE IS MY ISSUE
        'Return CInt(ms.GetBuffer()).ToString("X") ' to use HEX instead of Base64
        Return Convert.ToBase64String(ms.GetBuffer(), 0, CInt(ms.Length))
   Else
        Return Nothing
   End If
End Function

 


0
Curt_C
12/15/2006 5:05:53 PM
Reply: