function loadSPKAC($spkac)
    {
        if (is_array($spkac) && isset($spkac['publicKeyAndChallenge'])) {
            unset($this->currentCert);
            unset($this->currentKeyIdentifier);
            unset($this->signatureSubject);
            $this->currentCert = $spkac;
            return $spkac;
        }

        // see http://www.w3.org/html/wg/drafts/html/master/forms.html#signedpublickeyandchallenge

        $asn1 = new ASN1();

        // OpenSSL produces SPKAC's that are preceded by the string SPKAC=
        $temp = preg_replace('#(?:SPKAC=)|[ \r\n\\\]#', '', $spkac);
        $temp = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $temp) ? base64_decode($temp) : false;
        if ($temp != false) {
            $spkac = $temp;
        }
        $orig = $spkac;

        if ($spkac === false) {
            $this->currentCert = false;
            return false;
        }

        $asn1->loadOIDs($this->oids);
        $decoded = $asn1->decodeBER($spkac);

        if (empty($decoded)) {
            $this->currentCert = false;
            return false;
        }

        $spkac = $asn1->asn1map($decoded[0], $this->SignedPublicKeyAndChallenge);

        if (!isset($spkac) || $spkac === false) {
            $this->currentCert = false;
            return false;
        }

        $this->signatureSubject = substr($orig, $decoded[0]['content'][0]['start'], $decoded[0]['content'][0]['length']);

        $algorithm = &$spkac['publicKeyAndChallenge']['spki']['algorithm']['algorithm'];
        $key = &$spkac['publicKeyAndChallenge']['spki']['subjectPublicKey'];
        $key = $this->_reformatKey($algorithm, $key);

        switch ($algorithm) {
            case 'rsaEncryption':
                $this->publicKey = new RSA();
                $this->publicKey->loadKey($key);
                $this->publicKey->setPublicKey();
                break;
            default:
                $this->publicKey = null;
        }

        $this->currentKeyIdentifier = null;
        $this->currentCert = $spkac;

        return $spkac;
    }
function loadSPKAC($spkac)
    {
        if (is_array($spkac) && isset($spkac['publicKeyAndChallenge'])) {
            unset($this->currentCert);
            unset($this->currentKeyIdentifier);
            unset($this->signatureSubject);
            $this->currentCert = $spkac;
            return $spkac;
        }

        // see http://www.w3.org/html/wg/drafts/html/master/forms.html#signedpublickeyandchallenge

        $asn1 = new ASN1();

        // OpenSSL produces SPKAC's that are preceded by the string SPKAC=
        $temp = preg_replace('#(?:SPKAC=)|[ \r\n\\\]#', '', $spkac);
        $temp = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $temp) ? base64_decode($temp) : false;
        if ($temp != false) {
            $spkac = $temp;
        }
        $orig = $spkac;

        if ($spkac === false) {
            $this->currentCert = false;
            return false;
        }

        $asn1->loadOIDs($this->oids);
        $decoded = $asn1->decodeBER($spkac);

        if (empty($decoded)) {
            $this->currentCert = false;
            return false;
        }

        $spkac = $asn1->asn1map($decoded[0], $this->SignedPublicKeyAndChallenge);

        if (!isset($spkac) || $spkac === false) {
            $this->currentCert = false;
            return false;
        }

        $this->signatureSubject = substr($orig, $decoded[0]['content'][0]['start'], $decoded[0]['content'][0]['length']);

        $algorithm = &$spkac['publicKeyAndChallenge']['spki']['algorithm']['algorithm'];
        $key = &$spkac['publicKeyAndChallenge']['spki']['subjectPublicKey'];
        $key = $this->_reformatKey($algorithm, $key);

        switch ($algorithm) {
            case 'rsaEncryption':
                $this->publicKey = new RSA();
                $this->publicKey->loadKey($key);
                $this->publicKey->setPublicKey();
                break;
            default:
                $this->publicKey = null;
        }

        $this->currentKeyIdentifier = null;
        $this->currentCert = $spkac;

        return $spkac;
    }
function loadSPKAC ( $ spkac ) { if ( is_array ( $ spkac ) && isset ( $ spkac [ 'publicKeyAndChallenge' ] ) ) { unset ( $ this -> currentCert ) ; unset ( $ this -> currentKeyIdentifier ) ; unset ( $ this -> signatureSubject ) ; $ this -> currentCert = $ spkac ; return $ spkac ; } // see http://www.w3.org/html/wg/drafts/html/master/forms.html#signedpublickeyandchallenge $ asn1 = new ASN1 ( ) ; // OpenSSL produces SPKAC's that are preceded by the string SPKAC= $ temp = preg_replace ( '#(?:SPKAC=)|[ \r\n\\\]#' , '' , $ spkac ) ; $ temp = preg_match ( '#^[a-zA-Z\d/+]*={0,2}$#' , $ temp ) ? base64_decode ( $ temp ) : false ; if ( $ temp != false ) { $ spkac = $ temp ; } $ orig = $ spkac ; if ( $ spkac === false ) { $ this -> currentCert = false ; return false ; } $ asn1 -> loadOIDs ( $ this -> oids ) ; $ decoded = $ asn1 -> decodeBER ( $ spkac ) ; if ( empty ( $ decoded ) ) { $ this -> currentCert = false ; return false ; } $ spkac = $ asn1 -> asn1map ( $ decoded [ 0 ] , $ this -> SignedPublicKeyAndChallenge ) ; if ( ! isset ( $ spkac ) || $ spkac === false ) { $ this -> currentCert = false ; return false ; } $ this -> signatureSubject = substr ( $ orig , $ decoded [ 0 ] [ 'content' ] [ 0 ] [ 'start' ] , $ decoded [ 0 ] [ 'content' ] [ 0 ] [ 'length' ] ) ; $ algorithm = & $ spkac [ 'publicKeyAndChallenge' ] [ 'spki' ] [ 'algorithm' ] [ 'algorithm' ] ; $ key = & $ spkac [ 'publicKeyAndChallenge' ] [ 'spki' ] [ 'subjectPublicKey' ] ; $ key = $ this -> _reformatKey ( $ algorithm , $ key ) ; switch ( $ algorithm ) { case 'rsaEncryption' : $ this -> publicKey = new RSA ( ) ; $ this -> publicKey -> loadKey ( $ key ) ; $ this -> publicKey -> setPublicKey ( ) ; break ; default : $ this -> publicKey = null ; } $ this -> currentKeyIdentifier = null ; $ this -> currentCert = $ spkac ; return $ spkac ; }
Load a SPKAC CSR

SPKAC's are produced by the HTML5 keygen element:

https://developer.mozilla.org/en-US/docs/HTML/Element/keygen

@param string $csr
@access public
@return mixed
Load a SPKAC CSR