php rsa實(shí)現(xiàn)的方法:首先創(chuàng)建“rsa_private_key.pem”和“rsa_public_key.pem”;然后判斷私鑰以及公鑰是否是可用的;接著獲取要加密的數(shù)據(jù);最后通過base64編碼轉(zhuǎn)換加密后的特殊字符即可。
創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、羅平網(wǎng)絡(luò)推廣、小程序制作、羅平網(wǎng)絡(luò)營銷、羅平企業(yè)策劃、羅平品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們大的嘉獎;創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供羅平建站搭建服務(wù),24小時(shí)服務(wù)熱線:13518219792,官方網(wǎng)址:jinyejixie.com
推薦:《PHP視頻教程》
php RSA 簡單實(shí)現(xiàn)
這是rsa_private_key.pem
-----BEGIN PRIVATE KEY----- MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCxsv3yAPRvIn2z j5zZcFCA6qnFUVjyRDNbQA2ni1vcnTlSjP9i0FNJgpZkRaDZ0PprH8t10mXnWtVd 9ZujztmHYWqETgGMGkq9fOou2/naFDXXUvtz2uhcUKCUYQUNXzfJPidfjmXe01OH eY8iN1X+GFo4LhumXgFIYsfBY8SKjeXgdiTl1Jhk+m+e27qRg0tD/kBVQ5vFmZmS 8g1QWU8RCAYi3N1UicVucLmjg3ORXkZ2jMB7DTQET8i2loGbTqpYzV5d3Ka0D8BS S7SBAdaipzU4RugaqveOAd2vCXfDtf9VWvdHPTN1OxEsYaJaKAZTYt/pK61wQ0BN 7dJUfSBTAgMBAAECggEAGRNJAn1gAM69Ljl1yLkwowB6NH3mL0mwdY/0XVAtBlSp YhzDbQ44soba8gthR1tV+wfhjh7CgoMu2LNv4w2tZI06mrDnRv3uzg5yfW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Wu+z50sIr2bnuGZAGgqVt8 9H+p1jGHtXrt2SWVAIpyWQ== -----END PRIVATE KEY-----
這是rsa_public_key.pem
-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsbL98gD0byJ9s4+c2XBQ gOqpxVFY8kQzW0ANp4tb3J05Uoz/YtBTSYKWZEWg2dD6ax/LddJl51rVXfWbo87Z h2FqhE4BjBpKvXzqLtv52hQ111L7c9roXFCglGEFDV83yT4nX45l3tNTh3mPIjdV /hhaOC4bpl4BSGLHwWPEio3l4HYk5dSYZPpvntu6kYNLQ/5AVUObxZmZkvINUFlP EQgGItzdVInFbnC5o4NzkV5GdozAew00BE/ItpaBm06qWM1eXdymtA/AUku0gQHW oqc1OEboGqr3jgHdrwl3w7X/VVr3Rz0zdTsRLGGiWigGU2Lf6SutcENATe3SVH0g UwIDAQAB -----END PUBLIC KEY-----
下面只需要加載即可
<?php #author:zk #data:2017-09-11 #note:php rsa secret $public_key = file_get_contents('./rsa_public_key.pem'); $private_key = file_get_contents('./rsa_private_key.pem'); //這個(gè)函數(shù)可用來判斷私鑰是否是可用的 $private_key = openssl_pkey_get_private($private_key); //這個(gè)函數(shù)可用來判斷公鑰是否是可用的 $public_key = openssl_pkey_get_public($public_key); //要加密的數(shù)據(jù) $data = "這是測試"; echo '加密的數(shù)據(jù):'.$data.'<br>'; //私鑰加密后的數(shù)據(jù) openssl_private_encrypt($data,$encrypted,$private_key); //加密后的內(nèi)容通常含有特殊字符,需要base64編碼轉(zhuǎn)換下 $encrypted = base64_encode($encrypted); echo "私鑰加密后的數(shù)據(jù):".$encrypted.'<br>'; //公鑰解密 openssl_public_decrypt(base64_decode($encrypted), $decrypted, $public_key); echo "公鑰解密后的數(shù)據(jù):".$decrypted.'<br>'; //----相反操作。公鑰加密 openssl_public_encrypt($data, $encrypted, $public_key); $encrypted = base64_encode($encrypted); echo "公鑰加密后的數(shù)據(jù):".$encrypted.'<br>'; openssl_private_decrypt(base64_decode($encrypted), $decrypted, $private_key);//私鑰解密 echo "私鑰解密后的數(shù)據(jù):".$decrypted.'<br>';
名稱欄目:phprsa如何實(shí)現(xiàn)
本文鏈接:http://jinyejixie.com/article10/cheddo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設(shè)、商城網(wǎng)站、網(wǎng)站排名、網(wǎng)站導(dǎo)航、網(wǎng)站營銷、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)