php公钥私钥 3 ---非标准格式转换为标准格式

PHP RSA 报错

openssl_sign(): supplied key param cannot be coerced into a private key

私钥

private function priKey(){

    $privateKey = 'MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCK9d1tCS/gJts5n/gGklJHP4510lWpgNyPcxvkXZJX3ej2vpE89ETofFJgcbBcpJqC7VOtRUEbHkVBZINMXqaacLdoLckHVltfq1b53hjAyuhb5UGKNqieAjGkWcNJmWe5wynj5U+hxdpX3UE9OwGrj7uwxmdXzoR3xTWLKNWFmtbBI4aC/aFDrh0McM54T/Mo9GOUVgg9BylKapnbJWav4NN4SyrEgKdyFpR7X2pj5RkZIEX6jdUtoYOS3h7XrCYyuLmKaEBKXoMN0Oi3KnqH7Vtj8e4lHqB92sY7NLtO9WoxmTU4Jtg5uWScw6GF8/2aQNOpdGgUZ3tivAKnpOXzAgMBAAECggEAfD7K5WPSd6OmXcanOBD6GhQ8pyIST4UVL/mm1a/IWmHim0PWjl6Fgi0uZmcgXiUatbfHGmSSitGs8IQTVWRHqEzh3/cYCERxXH/RO4YWMcL6sLexuweWCflCM4XCs3rDIHfca5Srd6R0zhzY6QtqOeBA3BT5b6wKCyC7+BnhmBt/2zB0ZQ+pybXx+lCX7nZkrExQjYXJzFfXGDSkIGiouBrnH33jMxmn8nUFZe7KioERGZQwrLdpV+vfE9vXlwnRb47RSFwwaW+KmEYuBIAp168Il3skaeHbU25ROaID3mWmSHxWhW3sVGQq7mvdI8g6GIdHfarTUs0UWIPcnzLeaQKBgQDPc4gCnppXV3qWm2Z1wX8Uv2bIKOYB6n6kpGlZt/PbM/dmKqtYqQdbweEKlkBAIPVqCcFL5/tnGBmOUuNxZPT/dnRFA8V1Cc85frSf9zX5VMb9bzzgzKHwc3a4968PyZfFyx+6GBfp1o2/YXRa0Me31QBhnDIVHnGjrG+/1X/2fQKBgQCrewZAc+UNX50ZYsYRyThnrGMx+XU1hudpVrdb8d/zvz7sgjCgc4lt9PYicQK7D3yAYpQPstnFzMavgvU/3qm18r29Io/CjjUARvS6QfUY68bk1jNt+IiMUMG1MnyvfYw1/ITjT0HVW2Vr9moJg9+fPr9CYSFg+SXWf9Sy5OFJLwKBgAGCiMHkH6F1HIpOFT/UKbWf8wKP8aSf7U4LeEzT3u2AglN3Cgo6KLiNP7MRBuSwmLit239O7/B/J2h2x/sCThox5YS/E0fXy29SscPcS8NFz7D2h03nj2ItpPaRru+Bex5QbSmwlTP5gMycy/kBPgLjhP4w4dhvgUo8rg+KYUUNAoGAayshxxonJmqBBiKC4w68n55PCCZ9KAy9h0nYoi/R5MW7D5h1x3EtjHixcujp6fpNtvbkzcLa8xF9gqb3mwkPS1T/W7rD2bWCTkAKJnWeNgr0bIOp9KqEvBykUxfQcOSnwf2lF2KrJCpQgl6n+nZeRWmzokqNz8sl6J5PUdZVLaUCgYAHrHSA0G3xRZGD18nTYoj2XMjbOql/5VMaoYecHiSmMZGhufBQGiDpPJZMHfcKbIOxh/dTMUxz54KhVj7p/ZfdevZenhJ65JVSSzAmvWB8OjwpkrTq85b66d9DrDshH46rUBc73FBdEsbY9q1CaAuDs7gN1aM0kv6wL49zRevRgQ==';

    $privateKey  = chunk_split($privateKey, 64, "\n");

    $privateKey = "-----BEGIN RSA PRIVATE KEY-----\n$privateKey-----END RSA PRIVATE KEY-----\n";

    return $privateKey;

}

公钥

public function pubKey(){

    $pub_key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAivXdbQkv4CbbOZ/4BpJSRz+OddJVqYDcj3Mb5F2SV93o9r6RPPRE6HxSYHGwXKSagu1TrUVBGx5FQWSDTF6mmnC3aC3JB1ZbX6tW+d4YwMroW+VBijaongIxpFnDSZlnucMp4+VPocXaV91BPTsBq4+7sMZnV86Ed8U1iyjVhZrWwSOGgv2hQ64dDHDOeE/zKPRjlFYIPQcpSmqZ2yVmr+DTeEsqxICnchaUe19qY+UZGSBF+o3VLaGDkt4e16wmMri5imhASl6DDdDotyp6h+1bY/HuJR6gfdrGOzS7TvVqMZk1OCbYOblknMOhhfP9mkDTqXRoFGd7YrwCp6Tl8wIDAQAB';

    $pub_key              = chunk_split($pub_key, 64, "\n");

    $pub_key = "-----BEGIN PUBLIC KEY-----\n$pub_key-----END PUBLIC KEY-----\n";

    return $pub_key;

}

你可能感兴趣的:(php公钥私钥 3 ---非标准格式转换为标准格式)