I want to encrypt a string whiche len is less than 16 character.
With the built-in library the encryption works only if the string is up to 16 character. How can i do for a string less than 16 characters
thanks in advance
AES ENCRYPTION
Re: AES ENCRYPTION
Pad it with spaces for the extra chars, then remove that many when decrypting. 

I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: AES ENCRYPTION
If you are just encoding a string, e.g. it is 0-terminated. You can just copy the string into a block of memory and where your sting fits with margin, the block then continues nicely with zeros. Reading it back will then also be very easy and it will be hard for somone to ues the length of the output (stored on disk?) to guess the original length.
Code: Select all
CompilerIf #PB_Compiler_Unicode
CompilerError "Should be compiled in ascii mode"
CompilerEndIf
#CrBlock=768
Define *Memory = AllocateMemory(#CrBlock)
Define *TPointer=*Memory
Define String$ = "Short"
If Len(String$)>=#CrBlock-1
Debug "Buffer To small"
CallDebugger
EndIf
CopyMemoryString(String$, @*TPointer)
Debug PeekS(*Memory)
*CipheredString = AllocateMemory(#CrBlock)
*DecipheredString = AllocateMemory(#CrBlock)
If AESEncoder(*Memory, *CipheredString, #CrBlock, ?Key, 128, ?InitializationVector)
Debug "Ciphered: "+PeekS(*CipheredString)
AESDecoder(*CipheredString, *DecipheredString, #CrBlock, ?Key, 128, ?InitializationVector)
Debug "Deciphered: "+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
The best preparation for tomorrow is doing your best today.
Re: AES ENCRYPTION
Ok I have a question If I encrypt some string and write it down in some txt file for example. After this how to decrypt it. When I try, I read the file and use the AESdecrypt but nothing's happen or the decrypted text is not the text that I've encrypted before this. 

Re: AES ENCRYPTION
When you save the encrypted data, you better use WriteData() or if you really(!) want it in ascii, use Base64Encoder().
Try this, if not working post a snippet back.
Try this, if not working post a snippet back.
The best preparation for tomorrow is doing your best today.