PHP 의 SSL 암호 화 설정

7184 단어 PHP
      
[Composer\Downloader\TransportException] The
"http://packages.zendframework.com/packages.json" file could not be downloaded: SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed Failed to enable crypto

구 글 을 뒤 집어 서...
      
~$ mkdir ~/tools/https-ca
 ~$ cd ~/tools/https-ca
 ~$ curl http://curl.haxx.se/ca/cacert.pem -o cacert.pem

   
/Users/jackluo/tools/https-ca/cacert.pem

    php.ini  
openssl.cafile=/Users/jackluo/tools/https-ca/cacert.pem

        

gitconfig   :
export GIT_CURL_VERBOSE=1 
~$ git config --global http.sslCAInfo /Users/jackluo/tools/https-ca/cacert.pem

   ~/.gitconfig  cainfo      git    

마음대로 소개 하 세 요. 암호 화 복호화:
function sign($data) {
    //      
    $priKey = file_get_contents('key/rsa_private_key.pem');
 
    //   openssl  ,       pkcs8     
    $res = openssl_get_privatekey($priKey);
 
    //  openssl      ,    $sign
    openssl_sign($data, $sign, $res);
 
    //    
    openssl_free_key($res);
 
    return $sign;
}

검증 검증 
function verify($data, $sign)  {
    //         
    $pubKey = file_get_contents('key/alipay_public_key.pem');
 
    //   openssl    
    $res = openssl_get_publickey($pubKey);
 
    //  openssl      ,  bool 
    $result = (bool)openssl_verify($data, $sign, $res);
     
    //    
    openssl_free_key($res);
 
    return $result;
}

복호화
function decrypt($content) {
 
    //      
    $priKey = file_get_contents('key/rsa_private_key.pem');
     
    //   openssl  ,       pkcs8     
    $res = openssl_get_privatekey($priKey);
 
    //         
    $result  = '';
 
    //    128   
    for($i = 0; $i < strlen($content)/128; $i++  ) {
        $data = substr($content, $i * 128, 128);
         
    //      128              ,  $decrypt      
        openssl_private_decrypt($data, $decrypt, $res);
 
    //      
        $result .= $decrypt;
    }
 
    //    
    openssl_free_key($res);
 
    //    
    return $result;
}

좋은 웹페이지 즐겨찾기