php加密方式:SHA256方法

**私钥加密:**
		ksort( $params );//数组排序
		$signData 		= implode( '', $params );
		$pi_key 			= openssl_pkey_get_private($rsaPriKey);//私钥
		$signature		='';
		openssl_sign( $signData, $signature, $pi_key, OPENSSL_ALGO_SHA256 );
		openssl_free_key($pi_key);
		$params['sign'] 	= base64_encode($signature);



**验证:**
		$sign = base64_decode($sign);
		//验证公钥是否可用
		$pu = openssl_get_publickey($this->merchant_public_key);
		//公钥验证
		$isSuccess = (bool)openssl_verify ($returnArray,$sign,$pu,OPENSSL_ALGO_SHA256);

你可能感兴趣的:(PHP,后端)