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.
Thanks,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
Looking forward to your help!![]()




Reply With Quote