
AES problem
AES problem
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 

- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: AES problem
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
BERESHEIT
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: AES problem
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.
BERESHEIT
Re: AES problem
Damn you are the man THANK you a lot AGAIN 

- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada