diff options
author | friendica <info@friendica.com> | 2014-08-14 23:05:19 -0700 |
---|---|---|
committer | friendica <info@friendica.com> | 2014-08-14 23:05:19 -0700 |
commit | 1978500e8ffb8ffdffd2d2969cbafb6f43b9dde4 (patch) | |
tree | 562e6c06817fb7594bce32f1f9539efd71415d24 /include/crypto.php | |
parent | 21adbad4c1a0f9a7953c3c011a3669d09cfc2bb4 (diff) | |
download | volse-hubzilla-1978500e8ffb8ffdffd2d2969cbafb6f43b9dde4.tar.gz volse-hubzilla-1978500e8ffb8ffdffd2d2969cbafb6f43b9dde4.tar.bz2 volse-hubzilla-1978500e8ffb8ffdffd2d2969cbafb6f43b9dde4.zip |
pkcs1 to pkcs8 key conversion - this is a lot easier than parsing ASN.1 DER formats and rebuilding the darn things like we used to do. Check for illegal hex encoded album names in mod/photo so we don't throw php errors. Don't know where they come from but we get a lot of them.
Diffstat (limited to 'include/crypto.php')
-rw-r--r-- | include/crypto.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/include/crypto.php b/include/crypto.php index 33cdc10c0..d8d79eaea 100644 --- a/include/crypto.php +++ b/include/crypto.php @@ -127,3 +127,27 @@ function new_keypair($bits) { } +function pkcs1to8($oldkey) { + + if(strstr($oldkey,'BEGIN PUBLIC')) + return $oldkey; + + $oldkey = str_replace('-----BEGIN RSA PUBLIC KEY-----', '', $oldkey); + $oldkey = trim(str_replace('-----END RSA PUBLIC KEY-----', '', $oldkey)); + $key = 'MIICIjANBgkqhkiG9w0BAQEFAAOCAg8A' . str_replace("\n", '', $oldkey); + $key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "\n-----END PUBLIC KEY-----"; + return $key; +} + +function pkcs8to1($oldkey) { + + if(strstr($oldkey,'BEGIN RSA')) + return $oldkey; + + $oldkey = str_replace('-----BEGIN PUBLIC KEY-----', '', $oldkey); + $oldkey = trim(str_replace('-----END PUBLIC KEY-----', '', $oldkey)); + $key = str_replace("\n",'',$oldkey); + $key = substr($key,32); + $key = "-----BEGIN RSA PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "\n-----END RSA PUBLIC KEY-----"; + return $key; +}
\ No newline at end of file |