doulangpeng3933 2014-08-12 10:15
浏览 1080

Websocket服务器出现RSA_padding_check_PKCS1_type_2错误

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?

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!