<?php

header("Content-Type: text/html; charset=utf-8");

$filename = dirname(__FILE__)."/payPublicKey.pem";//生成的公钥或私钥文件
    
    @chmod($filename, 0777);
    @unlink($filename);

$devPubKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDr6H/ictALLsV9/63lPFSYDPQKgRwEM2FiewfR/BYaPGfpgdl8lelNYqFxnqBRKbGnbFOwOxOu7oiiPYaJxcSU94hId3S0/UsSXyRfTaHT8ZZv+5luikQAG62hwkxqcSdL3aEMbqsHRfQ9RXiFAneiJJwZ1D0nHPANfBA4UN+OXQIDAQAB";//公钥或私钥


$begin_public_key = "-----BEGIN PUBLIC KEY-----\r\n"; //-----BEGIN PRIVATE KEY-----
$end_public_key = "-----END PUBLIC KEY-----\r\n";  //-----END PRIVATE KEY-----

$fp = fopen($filename,'ab');
fwrite($fp,$begin_public_key,strlen($begin_public_key));
$raw = strlen($devPubKey)/64;
$index = 0;
while($index <= $raw ) {
$line = substr($devPubKey,$index*64,64)."\r\n";
if(strlen(trim($line)) > 0)
fwrite($fp,$line,strlen($line));
$index++;
}
fwrite($fp,$end_public_key,strlen($end_public_key));
fclose($fp);
?>