Code: Select all
InitNetwork()
key.s = "12345678901234567890123456789012"
InitializationVector.s = "0987654321098765"
String$ = "string coming from the client..."
lenth.i = StringByteLength(String$,#PB_Ascii)
*string = AllocateMemory(lenth+1,#PB_Memory_NoClear)
Debug PokeS(*string,String$,lenth,#PB_Ascii)
StringMemorySize.i = lenth + 1; Space for the string and its null terminating character
*CipheredString = AllocateMemory(StringMemorySize,#PB_Memory_NoClear)
*DecipheredString = AllocateMemory(StringMemorySize,#PB_Memory_NoClear)
outsize.i = StringMemorySize*3; for Base64
*str = AllocateMemory(outsize,#PB_Memory_NoClear); for Base64
If AESEncoder(*string, *CipheredString, lenth, @Key, 256, @InitializationVector,#PB_Cipher_CBC)
Debug StringByteLength(String$)
Debug MemorySize(*CipheredString)
Debug StringMemorySize
i = Base64EncoderBuffer(*CipheredString, lenth,*str,outsize)
Debug "base64 = " + i
Debug "str = " + PeekS(*str,i,#PB_Ascii)
Debug "str = " + PeekS(*str,i,#PB_UTF8)
Debug "str = " + PeekS(*str,i,#PB_Unicode)
*Decoded = AllocateMemory(1024)
Debug "decode = " + Base64DecoderBuffer(@cmd,StringByteLength(cmd),*Decoded, 1024)
i=AESDecoder(*Decoded, *DecipheredString, lenth, @Key, 256, @InitializationVector)
Debug "Deciphered: "+PeekS(*DecipheredString,i,#PB_UTF8)
Debug "Deciphered: "+PeekS(*DecipheredString,i,#PB_Unicode)
Debug "Deciphered: "+PeekS(*DecipheredString,i,#PB_Ascii)
EndIf
Debug "ok"
Code: Select all
<?php
function fnDecrypt($sValue, $key, $iv) {
$cipher="AES-256-CBC";
return openssl_decrypt($sValue, $cipher, $key, 0, $iv);
}
$key = "12345678901234567890123456789012";
$iv = "0987654321098765";
$str = "/F/9WXb7y6j1tOcKTmFy608wO2BFo8jZ1HUo4+oPUG9AQ/UyY1KxVcVbNfDtRNAQdIqseKNuK5DPpkhooAxVBAAA";
$newStr = fnDecrypt($str, $key, $iv);
echo "<br/>str = " . $str;
echo "<br/>new = " . $newStr;
?>