示例#1
0
 public function __construct($xmlRsakey = null, $type = null)
 {
     $xmlObj = null;
     if ($xmlRsakey == null) {
         $xmlObj = simplexml_load_file("xmlfile/RSAKey.xml");
     } elseif ($type == self::XMLFile) {
         $xmlObj = simplexml_load_file($xmlRsakey);
     } else {
         $xmlObj = simplexml_load_string($xmlRsakey);
     }
     $this->modulus = Rsa::binary_to_number(base64_decode($xmlObj->Modulus));
     $this->public_key = Rsa::binary_to_number(base64_decode($xmlObj->Exponent));
     $this->private_key = Rsa::binary_to_number(base64_decode($xmlObj->D));
     $this->key_length = strlen(base64_decode($xmlObj->Modulus)) * 8;
 }
示例#2
0
 function sign($message, $private_key, $modulus, $keylength)
 {
     $padded = Rsa::add_PKCS1_padding($message, false, $keylength / 8);
     $number = Rsa::binary_to_number($padded);
     $signed = Rsa::pow_mod($number, $private_key, $modulus);
     $result = Rsa::number_to_binary($signed, $keylength / 8);
     return $result;
 }