为什么使用DSA签名的php代码在某些服务器上工作而在其他服务器上不工作?

时间:2011-10-31 19:21:22

标签: php linux dsa

我有以下php测试代码:

$priv_key = '-----BEGIN DSA PRIVATE KEY-----
MIIDVQIBAAKCAQEAgoiNtnpekz2WSBOiEO9bq73SEkws9OYxMyV7Tf3JBpBIIyvc
fci8ez+dLmFN3jZiDQKm7h/h70ainWjdHRMqQubv5M087fWnVbN7/vk4cpYOJ4AK
XpshLipJ93dajRBxGRSk709ykmK+fCcAuqCvsBl80d6hGqpnGDYb9h1g0/+afNm7
Wun/yA7QSpqmvqDu5fyp8s7Pa8sjFT7Yad/K8ZH6MeEl7hltiFjhpWRSdI5NCa0m
lxopbp0V8ekZgoTfYOLynTIXTJQxWc4dnELhFtQ//x6cle+XcXeU6fA+KvgrYJV2
QkWBfBmDXMByl/3GJ9ImyBFHT4WcaQnXf6KaZwIhAIZVyb3K2kt/BGYDCzrXBQAt
Y7IaPQ8njArMPSiXuxrBAoIBAFEKon1yjx4NlnnJ3S1KQawiB6Ct+UjR5wAf3WCk
+bE0nPbq02sHPDZTOAMpwd54O0nYIKoLT67cX17DMcV/yA2qcodZfKySDzEwleIS
hlNXUYOxMQ3hWP9L+Hamus0KvpXxiJ9ayXbCq7AD8wXujQPYyptazvW02ay9AQzZ
GydmVFYa00IfG7scSzneDRpafg0HB1HoG4Aer+WxMTWXlyc+4F+wEn5zCU6qrUAX
/x6qV4L6FDA7qIIUSbrdLekvrTe/1vo+59+LLp5T9oIl0oKSs1+Zdd7aZoeSH/j4
j73X79e6PdrmRcUlTW8bdXLsOsQcsttI9pDYM6FtO/t6d9ECggEAJv33pYZL4tFb
0x9MBZapgzybtYeDKMkXmU5cY1Sx20U5XV1+Hr5XKo5ccEiBHBLeII87wRasMM74
P1dzTvXxl4YIcKm8wfbLNSEpZnLqFYkS0Rnxo0LNMdL/r2pIT2oFAix4O7+twHee
R8IHmwT7JRHUiJaco2Va/fGpIHa8XannET3ItB0rw84nKJ4ikyfXqkJDPj85xcrW
43Vd+YZsWbzvSr41dfKEs5ZFz0JcyjVYM+csalq7lj7s9t+qkiI0YFw2qGk0cdp2
zks7lqknfMLvBTd2m5/gcz82JaqrZPA5FZ3SyYWWdZMMD7pubXteCaDBfdZaQyCQ
KfAwGF7SRgIgRTnow19Mz5gmWpgmSfIJSZ8aGDUxnm7Y4+1AQh/whU4=
-----END DSA PRIVATE KEY-----
';

$data = "test";//$_GET['i'];
// compute signature
if(!openssl_sign($data, $signature, $priv_key,OPENSSL_ALGO_DSS1)){
    echo "Failed to sign data: $data";
}
echo base64_encode($signature);


$pukeyid = '-----BEGIN PUBLIC KEY-----
MIIDRjCCAjkGByqGSM44BAEwggIsAoIBAQCCiI22el6TPZZIE6IQ71urvdISTCz0
5jEzJXtN/ckGkEgjK9x9yLx7P50uYU3eNmINAqbuH+HvRqKdaN0dEypC5u/kzTzt
9adVs3v++Thylg4ngApemyEuKkn3d1qNEHEZFKTvT3KSYr58JwC6oK+wGXzR3qEa
qmcYNhv2HWDT/5p82bta6f/IDtBKmqa+oO7l/Knyzs9ryyMVPthp38rxkfox4SXu
GW2IWOGlZFJ0jk0JrSaXGilunRXx6RmChN9g4vKdMhdMlDFZzh2cQuEW1D//HpyV
75dxd5Tp8D4q+CtglXZCRYF8GYNcwHKX/cYn0ibIEUdPhZxpCdd/oppnAiEAhlXJ
vcraS38EZgMLOtcFAC1jsho9DyeMCsw9KJe7GsECggEAUQqifXKPHg2WecndLUpB
rCIHoK35SNHnAB/dYKT5sTSc9urTawc8NlM4AynB3ng7SdggqgtPrtxfXsMxxX/I
Dapyh1l8rJIPMTCV4hKGU1dRg7ExDeFY/0v4dqa6zQq+lfGIn1rJdsKrsAPzBe6N
A9jKm1rO9bTZrL0BDNkbJ2ZUVhrTQh8buxxLOd4NGlp+DQcHUegbgB6v5bExNZeX
Jz7gX7ASfnMJTqqtQBf/HqpXgvoUMDuoghRJut0t6S+tN7/W+j7n34sunlP2giXS
gpKzX5l13tpmh5If+PiPvdfv17o92uZFxSVNbxt1cuw6xByy20j2kNgzoW07+3p3
0QOCAQUAAoIBACb996WGS+LRW9MfTAWWqYM8m7WHgyjJF5lOXGNUsdtFOV1dfh6+
VyqOXHBIgRwS3iCPO8EWrDDO+D9Xc0718ZeGCHCpvMH2yzUhKWZy6hWJEtEZ8aNC
zTHS/69qSE9qBQIseDu/rcB3nkfCB5sE+yUR1IiWnKNlWv3xqSB2vF2p5xE9yLQd
K8POJyieIpMn16pCQz4/OcXK1uN1XfmGbFm870q+NXXyhLOWRc9CXMo1WDPnLGpa
u5Y+7PbfqpIiNGBcNqhpNHHads5LO5apJ3zC7wU3dpuf4HM/NiWqq2TwORWd0smF
lnWTDA+6bm17XgmgwX3WWkMgkCnwMBhe0kY=
-----END PUBLIC KEY-----';

$valid = openssl_verify($data, $signature, $pukeyid, OPENSSL_ALGO_DSS1);
echo "<br/>Signature validity: ".$valid;

当我在亚马逊服务器上运行它时,它按预期工作。但是当我尝试将它转移到hostgator或ovh.co.uk上的共享主机时,它就会失败。

在hostgator上,它返回一个看起来有效的签名,但无法验证签名是否正确。在ovh.co.uk上它返回以下内容:

QA ==

签名有效期:-1

这显然是服务器的问题。应该修复什么才能起作用?

0 个答案:

没有答案