php openssl(SHA1WithRSA) 签名 验签

签名:

public function wjSign($data){
	$key = openssl_pkey_get_private(file_get_contents($this->privateKeyPathWJ));
	openssl_sign($data, $sign, $key, OPENSSL_ALGO_SHA1);
	$sign = base64_encode($sign);
	return $sign;
}

验签:

public function wjVerify($data, $sign){
	$sign = base64_decode($sign);
	$key = openssl_pkey_get_public(file_get_contents($this->publicKeyPathWJ));
	$result = openssl_verify($data, $sign, $key, OPENSSL_ALGO_SHA1) === 1;
	return $result;
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注