Created
January 28, 2018 09:50
-
-
Save zhangv/075415e3891f98179095c781a37f55a6 to your computer and use it in GitHub Desktop.
convert RSA PKCS#1 to PKCS#8
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
function convertPKCS1toPKCS8($pkcs1){ | |
$start_key = $pkcs1; | |
$start_key = str_replace('-----BEGIN RSA PUBLIC KEY-----', '', $start_key); | |
$start_key = trim(str_replace('-----END RSA PUBLIC KEY-----', '', $start_key)); | |
$key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' . str_replace("\n", '', $start_key); | |
$key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "\n-----END PUBLIC KEY-----"; | |
return $key; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment