+ /**
+ * Fill out $this->privateKey or $this->publicKey with a Crypt_RSA object
+ * representing the give key (as mod/exponent pair).
+ *
+ * @param string $mod base64-encoded
+ * @param string $exp base64-encoded exponent
+ * @param string $type one of 'public' or 'private'
+ */
+ public function loadKey($mod, $exp, $type = 'public')
+ {
+ common_log(LOG_DEBUG, "Adding ".$type." key: (".$mod .', '. $exp .")");
+
+ $rsa = new Crypt_RSA();
+ $rsa->signatureMode = CRYPT_RSA_SIGNATURE_PKCS1;
+ $rsa->setHash('sha256');
+ $rsa->modulus = new Math_BigInteger(Magicsig::base64_url_decode($mod), 256);
+ $rsa->k = strlen($rsa->modulus->toBytes());
+ $rsa->exponent = new Math_BigInteger(Magicsig::base64_url_decode($exp), 256);
+
+ if ($type == 'private') {
+ $this->privateKey = $rsa;
+ } else {
+ $this->publicKey = $rsa;
+ }
+ }
+
+ /**
+ * Returns the name of the crypto algorithm used for this key.
+ *
+ * @return string
+ */