Page 1 of 1

AES problem

Posted: Mon Jul 26, 2010 5:41 pm
by Krisko
Hi everybody. I have a little problem with the AES in PB. I know it is great for encoding. But when I use the example which is in the help file of PB I have a little problem. When I try to encode a string which is less than 16 characters, nothing is happen. Why it's happen like that. When I try to encode a string with 16 characters or more there is no problem. Please if some one can help me I'll be very grateful :)

Re: AES problem

Posted: Mon Jul 26, 2010 10:20 pm
by netmaestro
I think it must be 16 chars or more iirc. Here's how I'd solve it:

Code: Select all

; Should be compiled in ascii mode
  ;
  String$ = "Hello"
  If Len(string$)<16
    string$ = LSet(string$,16)
  EndIf
  
  
  *CipheredString   = AllocateMemory(Len(String$)+1) ; Space for the string and its
  *DecipheredString = AllocateMemory(Len(String$)+1) ; null terminating character (ASCII mode)
  
  If AESEncoder(@String$, *CipheredString, Len(String$), ?Key, 128, ?InitializationVector)
    Debug "Ciphered: "+PeekS(*CipheredString)
    
    AESDecoder(*CipheredString, *DecipheredString, Len(String$), ?Key, 128, ?InitializationVector)
    Debug "Deciphered: "+Trim(PeekS(*DecipheredString))
  EndIf

  DataSection
    Key:
      Data.b $06, $a9, $21, $40, $36, $b8, $a1, $5b, $51, $2e, $03, $d5, $34, $12, $00, $06
  
    InitializationVector:
      Data.b $3d, $af, $ba, $42, $9d, $9e, $b4, $30, $b4, $22, $da, $80, $2c, $9f, $ac, $41
  EndDataSection

Re: AES problem

Posted: Mon Jul 26, 2010 10:23 pm
by netmaestro
Also bear in mind that the PeekS(*cipheredstring) might show only part of the actual ciphered bytes because null-bytes do exist in AES ciphered memory blocks and as soon as PeekS hits one it'll quit.

Re: AES problem

Posted: Mon Jul 26, 2010 11:08 pm
by Krisko
Damn you are the man THANK you a lot AGAIN :mrgreen:

Re: AES problem

Posted: Tue Jul 27, 2010 1:22 am
by netmaestro
np, glad you got it worked out. :mrgreen: