Created
December 7, 2018 11:30
-
-
Save noname007/7da4a85ce512dc348ecf1542e5f8202f to your computer and use it in GitHub Desktop.
二进制流,字符串化后处理,反解回二进制流对应的 base_64_encode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$hex_str = 'e123476343f37e7ecfd8401b60897de9bcc1621e5ede9755e9c442fc9a16d41ee82e344f18135866ba1360f587346711255d8c40e5a5fb45958833f67c7487ac1ff5833716fcc6b7b0781d6fe38c1cb95f4ceeb99b17f62a927777a07103af379dc24d3e2ce0540838ee8f3549b3fb58083fbf7058d1cf6d7c15e9da03bf3709c61a79c2b2c858f327ed6755df7883c2130e9ba4b36fc366b7b72d0459c2ea326af189887ef213432e820beadc321791aa9fd708bbb3ab9c556e54beb8e15f88f07542030de04e0bbbf0537825f6d6761c919a93500099c83f8d00f7ba8b2b2e408e9f820c9390b8d1dba667c047b7adb3e3d2c3fdfd721f5998f80c5509299b'; | |
$len = strlen($hex); | |
$a = []; | |
for($i = 0; $i < $len; $i += 2) | |
{ | |
$a[] = chr((int)base_convert($hex[$i].$hex[$i + 1], 16, 10)); | |
} | |
echo count($a); | |
$bin_str = implode('', $a); | |
$pkey = "-----BEGIN PUBLIC KEY-----\n". | |
chunk_split(base64_encode($bin_str), 64, "\n") | |
. "-----END PUBLIC KEY-----"; | |
; | |
var_dump($pkey); |
Author
noname007
commented
Dec 7, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment