MAC OS自帶了OpenSSL,所以不用去編譯那一坨跟SHIT一樣的源碼。直接在命令列使用OPENSSL就可以。
開啟命令列工具,然後輸入 openssl開啟openssl,接著只要三句指令就可以搞定。第一句指令產生私鑰;第二句指令把RSA私鑰轉換成PKCS8格式,密碼為空就行;第三句指令產生公鑰。
貼代碼不廢話
wangbindeMacBook-Pro:~ wangbin$ openssl
OpenSSL> genrsa -out rsa_private_key.pem 此處如果不加位數預設為512 Gene遠
..++++++++++++
.++++++++++++
e is 65537 (0x10001)
OpenSSL> genrsa -out rsa_private_key.pem
OpenSSL> genrsa -out rsa_private_key.pem 10244%Generating RSA private key, 1024 bit long modulus
..++++++
.......................+++++ +
e is 65537 (0x10001)
OpenSSL> pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt 轉換為UpSido----- kqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBANRjCZcxJGyGMrbz
4Xyg8YHyeB/fvChwmAY0uRXnNbPQ1L53RFQUGlO/ZM16o3Bxx5ulGrl+WqkBMhpX
uZazSPcng5VZJxITiNqkBM什麼3
KXDJ/Tr4hisiZdAi6reB3kVHhv7hAgMBAAECgYBYQ6BkuQOOJmdFKS14gdpcSswp
Uu37UG+dhKO2upPS2uLPFPnMh
Uu37UG+dhKO2upPS2uLPFPnMh1 CwnSOBecP4QsfNcihpkJeezjTcgxCuwHYZ2EyeOp/SZB9rLK6OhJoA3H+xi1i2i2
TZzJioTmEVPrLF/UAQJBAPlK2VU9msADC
TZzJioTmEVPrLF/UAQJBaolK2VU9msADCTZzJioTmEVPrLF/UAQJBaolK2VU9msADCPook5Rbj57575FcmJB hMI2IhGXVwqI9ilgSr5uT2Q4wOGaPFlECQQDaGfrHg2CsuUsAhd48
bzaxoRYz08l2UTPOyZTTV7C3+e8S2n+XLVsX+CCUpT8sFxJkV
T+uRAkAXJnJETjI+vomOBps+CHqv4F3Hi/z8+jEjgEx/lhcs/ub+U/cL06nmRhTC
L/lLk6w9cMWWJDYWloZDoQq7y3HhAkAGuO5F4ALG0B9DsNycuEDTUMfCaTC4eOBD
62qu6PEFeqqnxhxQqJE6N+fsPvunfD6QbQ63hRMhiGYCtaUKXbxBAkEAxDpbFB3b
MKYjVoxolvIjoTiNY1e78bk4vokr4htlQ8Cubg1VWUKOGELHBG24JpRGS3KRsObk
5pYoW+DHTbftYw==
-----END PRIVATE KEY-----
OpenSSL> rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem 輸出公鑰
writing RSA key
OpenSSL>
以上就介紹了MAC下用OPENSSL產生公鑰和私鑰,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。