Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #42892 |

    Does someone have a code sample to perform an in-memory encryption/decrtyption for VB.Net? There is only a VB6 sample available, and the sample application does not convert from VB6 to .Net. I would really like to see the sample application of “Memory Encrypt” in a .Net environment. Can someone point me to that example?

    Thanks!!

    Imported from legacy forums. Posted by bitjcky (had 4243 views)

    User (Old forums)
    Member
    Post count: 23064

    If you take the Memory Envryption project in VB6, and convert it over to VB.Net using the standard MS conversion routine within Visual Studio, the project converts with 3 errors …

    In the routine MemoryEncrypt.cmdEncrypt_Click:
    vaDecryptedText = StrConv(txtDecryptedText.Text, vbFromUnicode)
    does not convert as vbFromUnicode is no longer supported within StrConv

    In the routine MemoryEncrypt.cmdDecrypt_Click:
    txtDecryptedText.Text = StrConv(vaDecrypted, vbUnicode)
    does not convert as vbUnicode is no longer supported within StrConv

    In the routine Utility.BinaryToHex:
    For I = 0 To LenB(vaBinaryValue) – 1
    does not convert as LenB is no longer supported.

    Replace code as follows:

    In the routine MemoryEncrypt.cmdEncrypt_Click:
    ‘vaDecryptedText = StrConv(txtDecryptedText.Text, vbFromUnicode)
    Dim asciiEnc As System.Text.Encoding = System.Text.Encoding.ASCII
    Dim unicodeEnc As System.Text.Encoding = System.Text.Encoding.Unicode
    Dim unicodebytes As Byte() = unicodeEnc.GetBytes(txtDecryptedText.Text)
    Dim asciiBytes As Byte() = System.Text.Encoding.Convert(unicodeEnc, asciiEnc, unicodebytes)
    vaDecryptedText = asciiBytes

    In the routine MemoryEncrypt.cmdDecrypt_Click:
    ‘txtDecryptedText.Text = StrConv(vaDecrypted, vbUnicode)
    Dim asciiEnc As System.Text.Encoding = System.Text.Encoding.ASCII
    Dim unicodeEnc As System.Text.Encoding = System.Text.Encoding.Unicode
    Dim asciiChars(asciiEnc.GetCharCount(vaDecrypted, 0, vaDecrypted.Length)) As Char
    asciiEnc.GetChars(vaDecrypted, 0, vaDecrypted.Length, asciiChars, 0)
    Dim asciiString As New String(asciiChars)
    txtDecryptedText.Text = asciiString

    In the routine Utility.BinaryToHex:
    ‘For I = 0 To LenB(vaBinaryValue) – 1
    For I = 0 To vaBinaryValue.length – 1

    You should be good to go.

    Imported from legacy forums. Posted by bitjcky (had 3492 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.