Jo, da gehört eigentlich noch ein Base64 dahinter.
Code: Alles auswählen
EnableExplicit
Procedure.s AES_String_Encode(String.s, *Key, Bits, *InitializationVector, Mode = #PB_Cipher_CBC)
	Protected *Output, Length, i, *Buffer, Result.s
	
	*Output = AllocateMemory(StringByteLength(String) * 2)
	Length  = AESEncoder(@String, *Output, StringByteLength(String), *Key, Bits, *InitializationVector, Mode)
	If Length
		*Buffer = AllocateMemory(StringByteLength(String) * 2)
		i       = Base64Encoder(*Output, Length, *Buffer, MemorySize(*Buffer))
		Result  = PeekS(*Buffer, i, #PB_Ascii)
		FreeMemory(*Output)
		FreeMemory(*Buffer)
	EndIf
	
	ProcedureReturn Result
EndProcedure
Procedure.s AES_String_Decode(String.s, *Key, Bits, *InitializationVector, Mode = #PB_Cipher_CBC)
	Protected *Output, Length, i, *Buffer, Result.s
	
	*Buffer = AllocateMemory(StringByteLength(String, #PB_Ascii) + 1)
	*Output = AllocateMemory(StringByteLength(String, #PB_Ascii) * 2)
	PokeS(*Buffer, String, -1, #PB_Ascii)
	i       = Base64Decoder(*Buffer, MemorySize(*Buffer) - 1, *Output, MemorySize(*Output))
	*Buffer = ReAllocateMemory(*Buffer, i * 2)
	Length  = AESDecoder(*Output, *Buffer, i, *Key, Bits, *InitializationVector, Mode)
	If Length
		Result = PeekS(*Buffer, Length / SizeOf(CHARACTER))
	EndIf
	FreeMemory(*Output)
	FreeMemory(*Buffer)
	
	ProcedureReturn Result
EndProcedure
;Example
Define String$, a$
String$ = "Hello this is a test for AES...¿"
a$ = AES_String_Encode(String$, ?Key, 128, ?InitializationVector)
Debug a$
Debug AES_String_Decode(a$, ?Key, 128, ?InitializationVector)
End
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