1. Jason Schultz
  2. PowerBuilder
  3. Wednesday, 11 September 2019

Hi,

I'm currently using PB2017R3 and attempting to utilize the new CrypterObject and CoderObject functionality.

I have a text file that contains encoded / encrypted information. I wish to open the file, read the file contents and decode/decrypt various data elements. I'm able to successfully open and read the contents of the file. For some data elements within the file, I need to decode and/or decrypt the current values. After performing a Base64Decode on a specific value (results in a Blob), I eventually end up with a value that appears to be a different character set than expected (extended ASCII?). 

I currently do the following:

Integer li_File_Return
Long ll_File_Read_Return
String ls_Raw_IV_Value, ls_IV_Value
Blob lblb_Decoded_IV_Value

CoderObject lcode_CoderObject
lcode_CoderObject = CREATE CoderObject

li_File_Return = FileOpen(as_in_file, TextMode!, Read!, Shared!, Append!, EncodingANSI!)
ll_File_Read_Return = FileReadEx(li_File_Return, ls_In_File_Contents)

//The following variable contains a base64 encoded value
ls_Raw_IV_Value = "4efJzlmwEH73IEP/ljoKlA=="

lblb_Decoded_IV_Value = lcode_CoderObject.Base64Decode(ls_Raw_IV_Value)
ls_IV_Value = String(lblb_Decoded_IV_Value, EncodingANSI!)

//The ls_IV_Value is now populated with: áçÉÎY°~÷ Cÿ–:”

Looking to see how to get the resulting decode value be regular text. I had expected to see a 16-digit alphanumeric value representing an initialization vector that will later be used for AES/CBC decryption. Not sure what I'm doing wrong. 

Thanks in advance for any guidance / suggestions.

Jason Schultz

 

Miguel Leeuwe Accepted Answer Pending Moderation
0
Votes
Undo

Not sure if this link could help you somehow:


https://www.appeon.com/standardsupport/search/view?id=3100

Comment
There are no comments made yet.
  1. Wednesday, 11 September 2019
  2. PowerBuilder
  3. # 1
Miguel Leeuwe Accepted Answer Pending Moderation
0
Votes
Undo

Yes, definitely, the problem is your input base 64 encoded value of "ls_Raw_IV_Value". It's not valid.

Replace the value with the one from the powerbuilder help on "Base64Decode" and you'll see what I mean. That one results correctly in "Test Base64":

-----------------------------------

//integer li_File_Return
//Long ll_File_Read_Return
String ls_Raw_IV_Value, ls_IV_Value
Blob lblb_Decoded_IV_Value

CoderObject lcode_CoderObject
lcode_CoderObject = CREATE CoderObject

//li_File_Return = FileOpen(as_in_file, TextMode!, Read!, Shared!, Append!, EncodingANSI!)
//ll_File_Read_Return = FileReadEx(li_File_Return, ls_In_File_Contents)

//The following variable contains a base64 encoded value
// ls_Raw_IV_Value = "4efJzlmwEH73IEP/ljoKlA==" // = incorrect value !!!
ls_Raw_IV_Value = "VGVzdCBCYXNlNjQ=" // from powerbuilder example in the help

lblb_Decoded_IV_Value = lcode_CoderObject.Base64Decode(ls_Raw_IV_Value)
ls_IV_Value = String(lblb_Decoded_IV_Value, EncodingANSI!)
destroy lcode_CoderObject

return

Comment
There are no comments made yet.
  1. Wednesday, 11 September 2019
  2. PowerBuilder
  3. # 2
Miguel Leeuwe Accepted Answer Pending Moderation
0
Votes
Undo

Am I right to suppose your "ls_Raw_IV_Value" has been determined by reading from the FileReadEx() result (or is it really correct that hardcoded assignment)?

Your code doesn't show what you do with "ls_In_File_Contents". Could it be that the error is in the correct value of "ls_Raw_IV_Value"?

If that could be the case, then maybe it's a good idea to use a blob variable instead of a string in FileReadEx. Then convert the blob to a string, using different encodings, to see if one of the encodings gives you better results.

Sorry that's all I can think of right now,

my 2cts.

Comment
Miguel,

Thank you for the suggestions. I agree that the value that I am attempting to Base64Decode() doesn't appear to be a true Base64 value. I also attempted to read into a blob and convert back to string utilizing all the different encoding types and all resulted in jibberish. Currently unsure how the value read from the source file was derived. We're currently attempting to replace existing encryption functionality that utilizes external .dlls and replace with native PB functionality. Unfortunately, the latest documentation that I have is still older and doesn't appear to align with the current functionality (since the older ingested file doesn't appear to contain the expected Base64 encoded value). I was using a source file (generated from the previous encryption .dlls) as a test case. Still a work in progress, but I appreciate the information / examples provided. It serves as a good resource. Will keep you all posted.
  1. Jason Schultz
  2. Thursday, 12 September 2019
Thanks Jason, sounds interesting.

Maybe the problem is that the file for FileOpen() is not AnsiEncoded! Could be a text file in for example UTF8!
  1. Miguel Leeuwe
  2. Thursday, 12 September 2019
There are no comments made yet.
  1. Wednesday, 11 September 2019
  2. PowerBuilder
  3. # 3
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.