I want to send a message from my SSL Website to my php-websocket server. The server uses a wildcard certificate.
This is the client:
var wsUri = "wss://ticket.qwellcode.de:9001";
websocket_qcode_intern = new WebSocket(wsUri);
And this my Websocket server:
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($socket, 0, $port);
socket_listen($socket);
...
To decrypt a message (e.g the header) I use the following code:
function decryptString($cryptText)
{
$keyFile=fopen("PATH/TO/pemfile.pem","r") or die("NOT FOUND");
$privateKey=fread($keyFile,8192);
fclose($keyFile);
openssl_get_privatekey($privateKey);
$binText = base64_decode($cryptText);
/* NOT WORK WITH THIS PADDING */
//openssl_private_decrypt($binText,$clearText,$privateKey,OPENSSL_PKCS1_PADDING);
openssl_private_decrypt($binText,$clearText,$privateKey);
print openssl_error_string();
return($clearText);
}
The problem is that with the padding "OPENSSL_PKCS1_PADDING" (or other paddings) I get the following message:
error:0407106B:rsa routines:RSA_padding_check_PKCS1_type_2:block
type is not 02
With the option "OPENSSL_NO_PADDING" I get crap decoded code like this:
▬♥☺ ø☺ ù♥☻→ª ↕ FRomTý¤▬3ŵ▬g»►F↕Ñ;nÏágdCH╝ *└
└ └‼└¶└↕└└◄ 3 2 E 9 8 ê ▬ / A 5 ä
♣ ♦☺ D ↑ ▬ ‼domain.de ☺ ☺
♠ ↨ ↑ ↓ ♂ ☻☺ # 3t ♣ ♣☺
I Use a SSL-Zetificat with the encryption, PKCS #1 SHA-1 - AES 128 CBC with SHA 1.
How can I decrypt this code ? ... I tryed everything .. And yes I know, I can use stream socket.. but I will solve this for me with the "normal" php-socket ...
Why am I having trouble decrypting? Is there a solution?