Results 1 to 3 of 3

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

Threaded View

  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.

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