Results 1 to 3 of 3

Thread: [2005] Encrypt 10 bytes into alphanumeric string <= 25 characters

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Location
    Philadelphia, PA
    Posts
    120

    Question [2005] Encrypt 10 bytes into alphanumeric string <= 25 characters

    Hi,

    I need to encrypt 10 bytes of info. into an alphanumeric string of no more than 25 characters that can be used as a product key.

    I will also need to decrypt the string back into the 10 bytes.

    First of all, is that even possible?
    I've tried various encryption methods from .NET cryptography namespace (ie. TripleDESCryptoServiceProvider) and I keep coming up with encryptions that are about 40 characters long.

    For example, the code below is one of the things I tried and will give me an alphanumeric string representing encrypted bytes but it will be too long to be used as a product key.

    Code:
    Private Function EncodeBytes(ByVal plainBytes() As Byte, ByVal key As String) As String
            Dim sEncodedString As String = ""
            Dim oDes As New Security.Cryptography.TripleDESCryptoServiceProvider
            Dim oPdb As New Security.Cryptography.PasswordDeriveBytes(key, New Byte(-1) {})
            Dim oMem As New IO.MemoryStream((plainBytes.Length))
            Dim encStream As New Security.Cryptography.CryptoStream(oMem, oDes.CreateEncryptor(), Security.Cryptography.CryptoStreamMode.Write)
            Dim encryptedBytes() As Byte = Nothing
    
            oDes.IV = New Byte(7) {}
            oDes.Key = oPdb.CryptDeriveKey("RC2", "SHA1", 128, oDes.IV)
            encStream.Write(plainBytes, 0, plainBytes.Length)
            encStream.FlushFinalBlock()
            ReDim encryptedBytes(CInt(oMem.Length - 1))
            oMem.Position = 0
            oMem.Read(encryptedBytes, 0, CInt(oMem.Length))
            encStream.Close()
    
            sEncodedString = ByteArrayToHexString(encryptedBytes) 'hex representation of encrypted bytes (can be used as a product if only it were shorter)
            'sEncodedString = Convert.ToBase64String(encryptedBytes) 'string will contain weird chars like +,/,= that can not be used in a product key.
            Return sEncodedString
        End Function
    Thanks,
    Looking forward to your help!
    Last edited by Nervotrep; Sep 21st, 2007 at 07:14 AM.

  2. #2
    Fanatic Member bgmacaw's Avatar
    Join Date
    Mar 2007
    Location
    Atlanta, GA USA
    Posts
    524

    Re: [2005] Encrypt 10 bytes into alphanumeric string <= 25 characters

    How secure do you need it to be?

    If it's doesn't have to be all that secure you can use XOR encryption like I describe in this article: 3 Handy VB.NET String Functions You Can Use. You can improve the security by doing some salting of the values, the more random, the better.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Location
    Philadelphia, PA
    Posts
    120

    Re: [2005] Encrypt 10 bytes into alphanumeric string <= 25 characters

    Quote Originally Posted by bgmacaw
    How secure do you need it to be?

    If it's doesn't have to be all that secure you can use XOR encryption like I describe in this article: 3 Handy VB.NET String Functions You Can Use. You can improve the security by doing some salting of the values, the more random, the better.
    Sorry that does not work for me.

    Does anyone else have any ideas?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width