Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

length of the data to decrypt is invalid rijndael

Posted on 2013-11-23
4
Medium Priority
?
936 Views
Last Modified: 2013-11-24
(I had this working a long time ago, now trying to re-construct it due to some computer issues.)

Private Function Encrypt(ByRef pPassPhrase As String, ByVal pTextToEncrypt As String) As String
        If pPassPhrase.Length > 16 Then
            'limitation of the encryption mechanism
            pPassPhrase = pPassPhrase.Substring(0, 16)
        End If
        If pTextToEncrypt.Trim.Length = 0 Then
            'the Text to encrypt not set!!!
            Return String.Empty
        End If
        Dim skey As New Encryption.Data(pPassPhrase)
        Dim sym As New Encryption.Symmetric(Encryption.Symmetric.Provider.Rijndael)
        Dim objEncryptedData As Encryption.Data
        objEncryptedData = sym.Encrypt(New Encryption.Data(pTextToEncrypt), skey)
        Return objEncryptedData.ToHex
    End Function

    Public Function Decrypt(ByRef pPassPhrase As String, ByVal pHexStream As String) As String
        Try
            Dim objSym As New Encryption.Symmetric(Encryption.Symmetric.Provider.Rijndael)
            Dim encryptedData As New Encryption.Data
            encryptedData.Hex = pHexStream
            Dim decryptedData As Encryption.Data
            decryptedData = objSym.Decrypt(encryptedData, New Encryption.Data(pPassPhrase))
            Return decryptedData.Text
        Catch ex As Exception

            Return ex.Message

        End Try
    End Function

Open in new window


The evaluation copy of my software generates a "lock" using the encryption method, a hard-coded passphrase, and the id of the user's motherboard.   For example, the result might look like this:

BFEBFBFF000306A9

When the user is ready to register the software, they send me the lock.  I enter it into a text box in my KeyMaker, which uses the Decrypt method to generate a "key".   I then send that key to the user.  The user enters the key into a dialog box that compares it to the lock and if everything matches, the software becomes a registered version.

The Keymaker software was lost due to some computer problems, but I remember enough to reconstruct it, except that I keep getting this error when I try to Decrypt the values entered into a text box:

"length of the data to decrypt is invalid"

I have seen numerous posts about this (enough to thoroughly confuse me), but most refer to the "cure" as changing both the encryption and decryption methods.  I would prefer not to change the encryption method if at all possible, as I am pretty happy with the way my software is working now and don't want to mess with it again.

I hope the issue is clear.

Thanks in advance for any and all responses!
cEncryption.vb
0
Comment
Question by:codefinger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39672283
>>but I remember enough to reconstruct it, except that I keep getting this error

To be honest that sounds like you do not remember enough.  If you don't have a copy of the encryption/decryption code then you have no other choice but to replace it with something else.
0
 

Author Comment

by:codefinger
ID: 39672646
The encryption and decryption code is what I posted.   It was copied from the source file of the software as it exists now and was working a long while ago.
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 39672741
Yes, but if it worked before and when you 'recode' it then it doesn't work.  That implies it isn't coded the same way as originally.
0
 

Author Closing Comment

by:codefinger
ID: 39673401
It's been awhile since I coded anything, guess I am getting rusty (and lazy!)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question