Пример #1
0
 static function convertRSA($modulus, $exponent)
 {
     /* make an ASN publicKeyInfo */
     $exponentEncoding = XMLSecurityKey::makeAsnSegment(0x2, $exponent);
     $modulusEncoding = XMLSecurityKey::makeAsnSegment(0x2, $modulus);
     $sequenceEncoding = XMLSecurityKey::makeAsnSegment(0x30, $modulusEncoding . $exponentEncoding);
     $bitstringEncoding = XMLSecurityKey::makeAsnSegment(0x3, $sequenceEncoding);
     $rsaAlgorithmIdentifier = pack("H*", "300D06092A864886F70D0101010500");
     $publicKeyInfo = XMLSecurityKey::makeAsnSegment(0x30, $rsaAlgorithmIdentifier . $bitstringEncoding);
     /* encode the publicKeyInfo in base64 and add PEM brackets */
     $publicKeyInfoBase64 = base64_encode($publicKeyInfo);
     $encoding = "-----BEGIN PUBLIC KEY-----\n";
     $offset = 0;
     while ($segment = substr($publicKeyInfoBase64, $offset, 64)) {
         $encoding = $encoding . $segment . "\n";
         $offset += 64;
     }
     return $encoding . "-----END PUBLIC KEY-----\n";
 }