Skip to content

Instantly share code, notes, and snippets.

@zhangv
Created January 28, 2018 09:50
Show Gist options
  • Save zhangv/075415e3891f98179095c781a37f55a6 to your computer and use it in GitHub Desktop.
Save zhangv/075415e3891f98179095c781a37f55a6 to your computer and use it in GitHub Desktop.
convert RSA PKCS#1 to PKCS#8
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