Esempio n. 1
0
 /**
  * Decode a string representation of an RSA public key or keypair
  * as a Magicsig object which can be used to sign or verify.
  *
  * @param string $text
  * @return Magicsig
  */
 public static function fromString($text)
 {
     $magic_sig = new Magicsig();
     // remove whitespace
     $text = preg_replace('/\\s+/', '', $text);
     // parse components
     if (!preg_match('/RSA\\.([^\\.]+)\\.([^\\.]+)(.([^\\.]+))?/', $text, $matches)) {
         return false;
     }
     $mod = $matches[1];
     $exp = $matches[2];
     if (!empty($matches[4])) {
         $private_exp = $matches[4];
     } else {
         $private_exp = false;
     }
     $magic_sig->loadKey($mod, $exp, 'public');
     if ($private_exp) {
         $magic_sig->loadKey($mod, $private_exp, 'private');
     }
     return $magic_sig;
 }